I have a simple app which uses several hubs, some in the same project and one in another class library, and everything is working fine. Now I want to try and load a hub that's been created at run-time using CSharpCodeProvider.CompileAssemblyFromSource, and have my client communicate with that hub. It's not showing up in /signalr/hubs/.
As one of several things I'm trying to get working, I'm trying to use a custom IAssemblyLocator as described here:
https://github.com/SignalR/SignalR/wiki/Extensibility
But my GetAssemblies() code isn't being called as far as I can tell. This is my Global.asax.cs:
protected void Application_Start()
{
GlobalHost.DependencyResolver.Register(typeof(IAssemblyLocator), () => new AssemblyLocator());
var config = new HubConfiguration
{
EnableCrossDomain = true
};
RouteTable.Routes.MapHubs(config);
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
and custom IAssemblyLocator:
public class AssemblyLocator : IAssemblyLocator
{
public IList< Assembly > GetAssemblies()
{
throw new Exception("I will break stuff");
IList<Assembly> allAsms = BuildManager.GetReferencedAssemblies().Cast<Assembly>().ToList();
foreach( Assembly asm in HubFactory.HubAssemblies )
{
allAsms.Add( asm );
}
return allAsms;
}
}
As you can see the first thing I'm doing is throwing an exception, just to prove that this code is being called, but it doesn't get thrown. With this code in place my application continues to work as normal, and my page/client can still send messages to my hubs.
For background, I would like several separate data feeds working on the same web page, using the one connection, using hubs created at run-time rather than compile time. So I need to be able to create and load a hub at run-time, have it appear in /signalr/hubs/. I'm pretty sure my run-time created hub is OK - I've taken the generated code, stuck it into a regular .cs file and included it at compile time, and it then shows up OK in /signalr/hubs. Don't seem to be able to use groups with one hub, because of the shared connection. I should be able to find my run-time created hubs fine using GetHubContext(string).
All ideas welcome!
MapHubs actually replaces the default resolver. Try changing the order.
var config = new HubConfiguration
{
EnableCrossDomain = true
};
RouteTable.Routes.MapHubs(config);
GlobalHost.DependencyResolver.Register(typeof(IAssemblyLocator), () => new AssemblyLocator());
来源:https://stackoverflow.com/questions/17063891/signalr-iassemblylocator-override-not-firing