You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a reference to the Autofac.WebApi2.Owin NuGet package.
In your application startup class, register the Autofac Web API middleware after registering the base Autofac middleware.
publicclassStartup{publicvoidConfiguration(IAppBuilderapp){varbuilder=newContainerBuilder();// STANDARD WEB API SETUP:// Get your HttpConfiguration. In OWIN, you'll create one// rather than using GlobalConfiguration.varconfig=newHttpConfiguration();// Register your Web API controllers.builder.RegisterApiControllers(Assembly.GetExecutingAssembly());// Run other optional steps, like registering filters,// per-controller-type services, etc., then set the dependency resolver// to be Autofac.varcontainer=builder.Build();config.DependencyResolver=newAutofacWebApiDependencyResolver(container);// OWIN WEB API SETUP:// Register the Autofac middleware FIRST, then the Autofac Web API middleware,// and finally the standard Web API middleware.app.UseAutofacMiddleware(container);app.UseAutofacWebApi(config);app.UseWebApi(config);}}
A common error in OWIN integration is use of the GlobalConfiguration.Configuration. In OWIN you create the configuration from scratch. You should not reference GlobalConfiguration.Configuration anywhere when using the OWIN integration.