SignalR IAssemblyLocator does not cancel

I have a simple application that uses several hubs, some in the same project, as well as in another class library, and everything works fine. Now I want to try downloading the hub that was created at runtime using CSharpCodeProvider.CompileAssemblyFromSource and associate my client with this hub. It does not appear in / signalr / hubs /.

As one of the few things I'm trying to get, I'm trying to use a custom IAssemblyLocator, as described here:

https://github.com/SignalR/SignalR/wiki/Extensibility

But my GetAssemblies () code is not 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 do is throw an exception, just to prove that this code is being called, but it is not being thrown. With this code, my application continues to work as usual, and my page / client can still send messages to my hubs.

For the background, I would like for several separate data feeds to work on the same web page, using the same connection, using hubs created at runtime, rather than compile time. Therefore, I need to be able to create and load a hub at runtime, appear in / signalr / hubs /. I am almost sure that my created hub is fully functional - I took the generated code, stuck it in a regular .cs file and included it at compile time, and then found OK in / signalr / hubs. It does not look like you can use groups with a single hub due to a shared connection. I should be able to find the created temporary hubs using GetHubContext (string).

All ideas are welcome!

+2
source share
1 answer

MapHubs actually replaces the default recognizer. Try changing the order.

 var config = new HubConfiguration { EnableCrossDomain = true }; RouteTable.Routes.MapHubs(config); GlobalHost.DependencyResolver.Register(typeof(IAssemblyLocator), () => new AssemblyLocator()); 
+2
source

Source: https://habr.com/ru/post/1497609/


All Articles