开发者

How to register Autofac component per http request in web.config?

In MVC3 application I h开发者_开发百科ave my custom implementation of IPrincipal.

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

Autofac XML-configuration has attribute "instance-scope" but it does not support "per-http-request".

Any ideas how can I register component per http scope in web.config?

I already tried different combinations of per-dependency, single-instance or per-lifetime-scope with ownership external but results are very buggy.


As Nicholas Blumhardt from Autofac team told me per-lifetime-scope should be used.

When running under ASP.NET it is equivalent to per-HTTP-request in practical terms.


As far as I can see from the source, registering per http request in XML configuration is not supported. As you mention, only the three instance-scope values (per-dependency, single-instance and per-lifetime-scope) are allowed.

Also, looking at how per-http-request scoping works, it uses the InstancePerMatchingLifetimeScope registration call with a httpRequest key. Again, there is no XML config way of configuring a "matching-lifetime-scope".

The way to go is configuration through code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜