问题
I'm using the Asp.Net boilerplate template with ASP.Net Core 2.1.
I implemented a Hub in the Web.Core assembly and created a controller.
I can subcribe/notify data with my hub from any client, this is not my problem.
I'd like to use this Hub in the Application Services layer, but SignalR is not referenced by Application Services layer by default.
So my question is :
Is it a bad practice to reference SignalR in the the Application Services layer ?
Thanks in advance !
Regards, Pierre-Luc
回答1:
Directly depending a web feature is not a good practice in the application layer. Because, it is assumed presentation layer independent.
I think you have a few options;
- If you think that you never change SignalR and you never use the application layer from another application, then you can directly reference to SignalR and use it. However, this should be the worst case.
- Abstract SignalR communication (define an interface) in the application layer and implement it in the web layer. In this case, it is good to define a Null implementation (search for "null object pattern" if you don't know) in the application layer to remove dependency and allow application layer to be usable without SignalR.
- If your application layer can not work with the null implementation (maybe it needs a real answer from the client) then you should think to move your SignalR depended code to the Web layer.
So, as like any good answer, it depends :)
来源:https://stackoverflow.com/questions/55472303/is-calling-a-signalr-hub-from-the-application-service-layer-a-bad-practice-in-as