将AutoFac与ASP.Net WebForms一起使用

时间:2012-07-27 02:10:14

标签: c# autofac

我阅读了官方文件,例如如下:

 public class Global : System.Web.HttpApplication
    {
        static IContainerProvider _containerProvider;

        public IContainerProvider ContainerProvider
        {
            get { return _containerProvider; }
        }

        protected void Application_Start(object sender, EventArgs e)
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<Foo>().As<IFoo>().HttpRequestScoped();

            _containerProvider = new ContainerProvider(builder.Build());
        }

这是我按照官方的例子做的,但问题是HttpRequestScoped方法不存在,为什么会这样?

另外,我想问一下如何在页面中获取接口实例和单例模式。

2 个答案:

答案 0 :(得分:0)

您需要添加using AutoFac.Integration.Web;

答案 1 :(得分:0)

我认为不再使用HttpRequestScoped。请尝试使用InstancePerHttpRequest()。