I'm completely new to both autofac and singalR libraries, so please be easy on me! I've got the following code in bootstrapper which works on its own without signalR.
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));
Above code works just fine but after registering my Hub with this below code, 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'm using SignalR dependency resolver binding to Autofac from this (https://github.com/pszmyd/SignalR.Autofac).
I've got a simple hub like this,
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've got when I tried to use DI to the hub.
"No scope with a Tag matching 'httpRequest' is visible from the scope in which the instance was requested."
No matter what I do, I can't seem to get it working and I'd be grateful if someone could please tell me what's wrong with the code above.
Many Thanks Leo