New MVC 4 web application using autofac 3.0 on IIS 7.5. How do I inject a dependency into an IHttpModule?
I tried constructor injection which resulted in:
Constructor on type 'AnonymousIdentityModule' not found
So it seems the internals require a parameterless constructor for http modules. I also tried property injection too but that resulted in no dependency actually being injected.
Registration
builder.RegisterType<AnonymousIdentityModule>().As<IHttpModule>().PropertiesAutowired().InstancePerHttpRequest();
IHttpModule Code
public class AnonymousIdentityModule : IHttpModule
{
private readonly IServiceManager _serviceManager;
// this causes "constructor not found" exception
public AnonymousIdentityModule(IServiceManager serviceManager)
{
_serviceManager = serviceManager;
}
// never assigned by autofac
public IServiceManager ServiceManager
{
get { return _serviceManager; }
set { _serviceManager = value; }
}
...
}
web.config
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<add name="AnonymousIdentityModule" type="AnonymousIdentityModule" />
</modules>
</system.webServer>
I found this old article related to Windsor but did not see an equivalent in autofac.