如何在web.config中为每个HTTP请求注册Autofac组件? [英] How to register Autofac component per http request in web.config?
问题描述
在MVC3应用程序中,我具有IPrincipal的自定义实现.
In MVC3 application I have my custom implementation of IPrincipal.
我想在web.config中注册它,然后通过Autofac将其注入到构造函数中.
I want to register it in web.config and then inject it to constructors by Autofac.
Autofac XML配置的属性为"instance-scope",但不支持"per-http-request".
Autofac XML-configuration has attribute "instance-scope" but it does not support "per-http-request".
有什么想法如何在web.config中为每个http作用域注册组件?
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.
推荐答案
正如Autofac团队的尼古拉斯·布鲁姆哈特(Nicholas Blumhardt)告诉我,应该使用每寿命范围.
As Nicholas Blumhardt from Autofac team told me per-lifetime-scope should be used.
在ASP.NET下运行时,实际上相当于每个HTTP请求.
When running under ASP.NET it is equivalent to per-HTTP-request in practical terms.
这篇关于如何在web.config中为每个HTTP请求注册Autofac组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!