我正在開發ASP.net Web窗體,並且我想要在網站中實現AutoFac。在asp.net web窗體中實現autofac
我遵循了以下鏈接步驟: https://code.google.com/p/autofac/wiki/WebFormsIntegration
但我得到這個錯誤:
This module requires that the HttpApplication (Global Application Class) implements IContainerProviderAccessor.
我無法找到我的項目Global.asax.cs
,只有Global.asax
。
Global.asax
:
<%@ Application Language="C#" %>
<%@ Import Namespace="Autofac" %>
<%@ Import Namespace="Autofac.Integration.Web" %>
<script RunAt="server">
public class Global : HttpApplication, IContainerProviderAccessor {
// Provider that holds the application container.
static IContainerProvider _containerProvider;
// Instance property that will be used by Autofac HttpModules
// to resolve and inject dependencies.
public IContainerProvider ContainerProvider {
get { return _containerProvider; }
}
void Application_Start(object sender, EventArgs e) {
// Code that runs on application startup
// Build up your application container and register your dependencies.
var builder = new ContainerBuilder();
//builder.RegisterType<SomeDependency>();
// ... continue registering dependencies...
// Once you're done registering things, set the container
// provider up with your registrations.
_containerProvider = new ContainerProvider(builder.Build());
}
}
</script>
任何想法?非常感謝你!
我已經在web.config中添加了,仍然有相同的錯誤... –