Search code examples
asp.net-coresignalronion-architecture

Using SignalR With between .NET Core projects


I have 2 projects in the same solution (one is MVC - project "A" and the other is a Web API - project "B") with Onion architecture

I am using SignalR to broadcast messages to clients:

The clients are connected trough a View (project "A") - when this view loads, data is also loaded into te view

When project "B" recieves some data, it calls the common service which saves data in the database and broadcasts the message to update the View in Project "A"

However, the data is not updated in real-time when project "B" calls this service, only when a manual refresh is done in the View on project "A", or when project "A" calls the service

Any thoughts? Kind regards


Solution

  • (Reposting my comment as an answer)

    Any thoughts?

    SignalR runs within a single application instance: multiple web-applications cannot both host the same SignalR instance.

    But what you can do, however, is to make Project-B become a SignalR client of Project-A so they can communicate that way. If you don't need two-way comms between A and B you could just add an ASP.NET Web API action/endpoint in A for B to invoke by sending a HTTP request to A - and inside this action/endpoint you'd do something with the DI-injected IHubContext<T>.

    (Use the Microsoft.AspNetCore.SignalR.Client NuGet package to allow any .NET application, even console programs and WIndows services, to be SignalR clients that can have 2-way communication with the SignalR-hosting web-application).