The problem is this line:
builder.RegisterModule(new AutofacWebTypesModule());
An exception message indicates that something is trying to resolve something from the scope with the httpRequest tag httpRequest . You get a register like this in Autofac when you register something with InstancePerHttpRequest() :
If you look at the source of AutofacWebTypesModule , it registers network abstractions (e.g. HttpContextBase , what you are looking for) as InstancePerHttpRequest .
Also, if you look at how Autofac.Integration.Mvc.AutofacDependencyResolver works, whenever you enable a type during a query, it creates a new, nested named scope over time with the httpRequest tag. This allows you to have the magic of InstancePerHttpRequest .
Assuming that the SignalR.Autofac library you use is here, here , which is also the one on NuGet ), looking at SignalR.Autofac.AutofacDependencyResolver , no such nested / named lifetime is created to allow the service .
Thus, when Autofac tries to resolve the HttpContextBase dependency, it cannot detect this area with httpRequest tags (because it does not exist) and throws an error that you see.
There is no simple answer for this . The httpRequest nested scope httpRequest really important, because it basically cannot exist outside of a real web request. This makes it “safe” - you cannot get an HttpContextBase if there is no web context (say, when you start the application).
If you need to enter HttpContextBase , and you are sure that your EventHub will live for only one web request and that it (I am not a SignalR guy, so bear with me), this means that you either need:
- Request a fix for this from the SignalR.Autofac project.
- Implement your own SignalR.Autofac.AutofacDependencyResolver, which handles things like the MVC converter does.
Without performing the work itself and checking it, I cannot give concrete instructions on how to do this. This exercise is provided to the reader.