该模块要求 HttpApplication 实现 IContainerProviderAccessor
你好 我想在我的 asp.net mvc 应用程序中使用 Autofac,这是我在 global.asxc 文件中的代码:
protected void Application_Start()
{
....
var builder = new ContainerBuilder();
builder.RegisterControllers(Assembly.GetExecutingAssembly());
IContainer container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
但是当我运行该项目时,我看到此错误:
此模块要求 HttpApplication(全局应用程序类)实现 IContainerProviderAccessor
怎么了 ?
Hi
I want to use Autofac in my asp.net mvc appliation and here is the code I have in global.asxc file :
protected void Application_Start()
{
....
var builder = new ContainerBuilder();
builder.RegisterControllers(Assembly.GetExecutingAssembly());
IContainer container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
but when I run the project, I see this error :
This module requires that the HttpApplication (Global Application Class) implements IContainerProviderAccessor
what is wrong ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我和OP遇到了同样的问题,但我的解决方案不同。
来自此处:
I had the same problem as the OP, but my solution was different.
From here:
asp.net mvc3 的 autofac 的最小 global.asax.cs 设置可能如下所示:
(RegisterRoutes 已从代码中删除)。与以前版本的 asp.net mvc 不同(来自 http://code.google.com /p/autofac/wiki/Mvc3Integration)
您还需要对 Autofac.Integration.Mvc.dll 的引用
A minimal global.asax.cs setup for autofac for asp.net mvc3 could look like this:
(RegisterRoutes is removed from the code). As opposed to previous versions of asp.net mvc (from http://code.google.com/p/autofac/wiki/Mvc3Integration)
You will also need a reference to Autofac.Integration.Mvc.dll