How to register an Autofac component for each HTTP request in web.config?

In an MVC3 application, I have a custom IPrincipal implementation.

I want to register it in web.config and then add it to Autofac constructors.

Autofac's XML configuration configuration has an instance scope attribute, but does not support per-http-request.

Any ideas how I can register a component for each HTTP scope in web.config?

I have already tried different combinations of dependency, single-instance or lifespan with ownership, but the results are very erroneous.

+2
source share
2 answers

As Nicolas Blumhardt of the Autofac team said, .

When working in ASP.NET, it is almost equivalent to requesting an HTTP request.

+3
source

As far as I can see from the source, registering an HTTP request in an XML configuration is not supported. As you can mention, only three instance-scope values ​​are allowed (for each of the dependencies, for one instance, and for life expectancy).

Also, looking at how the per-http-request scope works, it uses the InstancePerMatchingLifetimeScope registration call with the httpRequest key. Again, there is no way to configure a match-to-lifetime XML configuration.

The configuration path is code configuration.

+1
source

All Articles