I have an ASP.NET Core solution with multiple projects for API, Services, Data etc. Now I want to add a SignalR hub to my solution. For generating the payload before sending messages to clients, I want to have a service. But I can't create it in the Services project as the API project depends on it and SignalR is in the API project. I'd like to know what would be the best approach to achieve this. Alternate design ideas will be appreciated too.
CodePudding user response:
I'm pretty sure you can define your hub in a class library so it's not in your API project.
Alternatively
- declare a "Messaging Interface" in another library
- Reference that library and implement the interface in your API project. That implementor will take care of talking to the hub.
- Reference the interface (instead of hub directly) from your service.
- Pass in to service method (or register in DI) the implementor of the messaging interface so that your service can request the interface and have the implementor of choice (in the API project) do the work.