I have a webapi project where I have configured SignalR hub. I am able to send messages to client from within the api project but I have to send the messages from the repository project.
MyAAPIProject > Controller:
[HttpGet]
[Route("test")]
public IHttpActionResult UpdateEmployees()
{
_empRepo.Update();
// This is working fine =>
// MessageHub hub = new MessageHub();
// hub.SendMessage("something");
}
MyAPIProject > SignalR Hub:
namespace MyAPIProject.Hubs
{
public class MessageHub : Hub
{
public async void SendMessage(MessageDto p, string connectionId)
{
await Context.Clients.Client(connectionId).OnProgress(p);
}
}
}
I have added SignalRHub in WebApi project because as per documentation, we need to configure signalr in OWIN Startup class which can only be called in web projects(like my webapi project) not in class libraries(like my repository project).
MyAPIProject > StartUp:
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapAzureSignalR(this.GetType().FullName);
}
}
RepositoryProject > EmpRepo:
public void Update()
{
<<some task>>
// This is what I want to do =>
// MessageHub hub = new MessageHub();
// hub.SendMessage("something");
<<some task>>
}
Basically, from my webapi controller method, I am calling a repository(separate project) method which does the entire task and has to send task progress at regular intervals. In order to use SignalRHub to send message, I'll have to reference webapi project from repository.
But I am afraid that this will create circular dependency.
Can anyone please suggest how can I achieve this functionality without circular dependency?