public void ConfigureContainer(IAppBuilder app) { ContainerBuilder builder = new ContainerBuilder(); DependencyRegistrator.RegisterModules(builder); Assembly assembly = typeof(WebApiApplication).Assembly; // WebApi HttpConfiguration config = GlobalConfiguration.Configuration; // This for OWIN integration(OWIN hosting): HttpConfiguration config = new HttpConfiguration(); builder.RegisterApiControllers(assembly); // OPTIONAL: Register the Autofac filter provider: builder.RegisterWebApiFilterProvider(config); // MVC builder.RegisterControllers(assembly); IContainer container = builder.Build(); // MVC DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); // WebApi config.DependencyResolver = new AutofacWebApiDependencyResolver(container); app.UseAutofacMiddleware(container); app.UseAutofacWebApi(config); app.UseAutofacMvc(); }
private void RegisterDependencies(ContainerBuilder builder) { DependencyRegistrator.RegisterModules(builder); }