I'm completely new to autofac and singalR, so please be calm! I have the following code in bootstrapper that works on its own without a signal.
var builder = new ContainerBuilder(); builder.RegisterControllers(Assembly.GetExecutingAssembly()); builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).AsImplementedInterfaces(); builder.RegisterType<DatabaseFactory>().As<IDatabaseFactory>().InstancePerHttpRequest(); builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerHttpRequest(); builder.RegisterAssemblyTypes(typeof(adminRepository).Assembly).Where(t => t.Name.EndsWith("Repository")).AsImplementedInterfaces().InstancePerHttpRequest(); builder.RegisterAssemblyTypes(typeof(adminService).Assembly).Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces().InstancePerHttpRequest(); builder.RegisterFilterProvider(); IContainer container = builder.Build(); DependencyResolver.SetResolver(new Autofac.Integration.Mvc.AutofacDependencyResolver(container));
The code above works fine, but after registering my hub with this code below, it just doesn't work.
builder.RegisterType<Chat>().InstancePerLifetimeScope(); builder.RegisterFilterProvider(); IContainer container = builder.Build(); DependencyResolver.SetResolver(new Autofac.Integration.Mvc.AutofacDependencyResolver(container)); SignalR.IDependencyResolver resolver = new SignalR.Autofac.AutofacDependencyResolver(container); GlobalHost.DependencyResolver = resolver; RouteTable.Routes.MapHubs(resolver);
I am using SignalR dependency binding binding to Autofac from this (https://github.com/pszmyd/SignalR.Autofac).
I have such a simple hub
public class Chat : Hub { private readonly IadminService adminService; public Chat(IadminService adminService) { this.adminService = adminService; } public void Send(string message) { Clients.addMessage(message); } }
This is the error I received when I tried to use DI in a hub.
"No area with a tag matching" httpRequest "is visible from the area in which the instance was requested.
No matter what I do, I cannot get it to work, and I would appreciate if anyone could tell me what happened to the code above.
Many thanks Leo
Leo source share