I have a scenario as such.
A base class which modules are derived from.
Each module has it's own signalr hubs.
I want to host all modules in a single host, separated by module name.
Some modules will share hub names.
namespace domain.com.base
{
public class BaseClass
{
public string ApplicationName;
}
}
namespace domain.com.billing
{
public class Billing : BaseClass
{
ApplicationName = "Billing";
}
public class NotificationHub : Hub
{
public void Credit(decimal amount)
{
Clients.All.Notify(amount);
}
}
}
namespace domain.com.reporting
{
public class Reporting : BaseClass
{
ApplicationName = "Reporting";
}
public class ReportingHub : Hub
{
public Report GetReport(int Id)
{
return ReportModule.RetrieveReport(Id);
}
}
}
In OWIN.Startup.Configuration(IAppBuilder) is it possible to do something like such
namespace domain.com.external_access
{
public void Configuration(IAppBuilder app)
{
var asmList = GlobalResolver.Applications();
foreach(var asm in asmList)
{
app.MapSignalR(asm.ApplicationName,false);
}
}
}
Effectively giving you something like so...
http://domain.com.external_access/Reporting/hubs http://domain.com.external_access/Billing/hubs
Actually this is doable, even if it requires some heavy working-around SignalR's tight coupling around GlobalHost
.
The answer below is based on what I remember, I don't have access to my code right now. I'll update the answer asap if errors are in there.
Edit: I had it right yesterday evening. Just do as written below
You'll need to implement your own IHubDescriptorProvider
and IHubActivator
in order to have control over which Hub
are found for each of your "endpoints". Furthermore you need to provide each endpoint with their own instance of HubConfiguration
(which inherits from ConnectionConfiguration
) that doesn't use the global host dependency resolver. Here's what this could look like:
class CustomSignalRConnectionConfiguration : HubConfiguration
{
public CustomSignalRConnectionConfiguration()
{
this.Resolver = new DefaultDependencyResolver();
// configure your DI here...
var diContainer = new YourFavouriteDi();
// replace IHubActivator
this.Resolver.Register(
typeof(IHubActivator),
() => diContainer.Resolve<IHubActivator>());
// replace IHubDescriptorProvider
this.Resolver.Register(
typeof(IHubDescriptorProvider),
() => diContainer.Resolve<IHubDescriptorProvider>());
}
}
For your single endpoints you could then do something like:
app.Map("/endpointName", mappedApp =>
{
var config = new CustomSignalRConnectionConfiguration();
mappedApp.MapSignalR(config);
});
Good luck!