Is calling a SignalR Hub from the Application Service Layer a bad practice in ASP.Net Boilerplate?

こ雲淡風輕ζ 提交于 2020-01-24 09:33:26

问题




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;

  1. 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.
  2. 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.
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!