I am writing a small web application and want to use signalr to generate push notifications, but when I load hubs from another assembly, nothing happens.
here is my build locator, from another library that references my asp.net mvc project
public class HubAssemblyLocator : IAssemblyLocator { public IList<Assembly> GetAssemblies() { IList<Assembly> allAsms = BuildManager.GetReferencedAssemblies().Cast<Assembly>().ToList(); var executingDirectory = AppDomain.CurrentDomain.BaseDirectory; var assemblyFiles = Directory.EnumerateFiles( executingDirectory, "Application" ); foreach ( var assemblyFile in assemblyFiles.Where( _ => _.EndsWith( ".dll" ) ) ) { var asm = Assembly.LoadFile( assemblyFile ); if ( asm.GetTypes().Any( _ => _.BaseType == typeof( Hub ) ) ) { allAsms.Add( asm ); } } return allAsms; } }
Here is my ApplicationStart event in Global.asax
public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register( GlobalConfiguration.Configuration ); FilterConfig.RegisterGlobalFilters( GlobalFilters.Filters ); RouteConfig.RegisterRoutes( RouteTable.Routes ); InitializeRepositories.Initialize(); var servicesPre = GlobalHost.DependencyResolver.GetServices( typeof( IAssemblyLocator ) ); RouteTable.Routes.MapHubs(new HubConfiguration() { EnableCrossDomain = true}); GlobalHost.DependencyResolver.Register( typeof( IAssemblyLocator ), () => new HubAssemblyLocator() ); var servicesPost = GlobalHost.DependencyResolver.GetServices(typeof (IAssemblyLocator)); } }
In this issue this problem is solved, but in my situation it does not work.
SignalR IAssemblyLocator is not running
And in my situation, the assembly locator fails.
Update: just register nodes before registering areas and routes.
source share