I'm fairly new to SignalR. I started writing a hub and putting that logic in a class library.
Here's what I'm trying to accomplish:
I have a "preprocessor" service that goes off and pre-fetches a number of objects/documents/etc from external sources and puts them into the cache. I am using the hub to communicate to clients when all items have been pre-fetched.
We also have several client consumers. Among them include:
The problem
By putting the hub in the class library, I've made all the downstream consumers (including other class libraries) have a dependency on OWIN... and I now need my startup class (and or app config settings to tell Owin to not use it).
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
or
<add key="owin:AutomaticAppStartup " value="false" />
The Architecture?
This 'smells' to me. Maybe SignalR hubs are not meant to be in a class library? If that is the case, what would be a better design? e.g. have the hub in its own WebApi Service? And proxies to this service? That way, my preprocessor logic (contained in a class library) can call the Hub?
Suggestions would be greatly appreciated.
SignalR can be used to add any sort of "real-time" web functionality to your ASP.NET application. While chat is often used as an example, you can do a whole lot more. Any time a user refreshes a web page to see new data, or the page implements long polling to retrieve new data, it is a candidate for using SignalR.
What is a SignalR hub. The SignalR Hubs API enables you to call methods on connected clients from the server. In the server code, you define methods that are called by client. In the client code, you define methods that are called from the server.
SignalR is a free and open-source software library for Microsoft ASP.NET that allows server code to send asynchronous notifications to client-side web applications. The library includes server-side and client-side JavaScript components.
SignalR uses encryption and a digital signature to protect the connection token. For each request, the server validates the contents of the token to ensure that the request is coming from the specified user.
You can have your SignalR stuff in a class library for sure, but in your case that should probably be a different one from the one you have where the preprocessing happens. The SignalR one would be pure infrastructure, and no business logic would happen, just messaging. You can define some interface in the middle and plug the infrastructure into your preprocessing one. This way the dependency on SignalR is behind an interface, your code is clean, and the dependency on Owin is isolated into the infrastructure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With