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
To get Autofac integrated with MVC you need to reference this MVC integration NuGet package, register your controllers, and set the dependency resolver. You can optionally enable other features as well.
protectedvoidApplication_Start(){varbuilder=newContainerBuilder();// Register your MVC controllers. (MvcApplication is the name of// the class in Global.asax.)builder.RegisterControllers(typeof(MvcApplication).Assembly);// OPTIONAL: Register model binders that require DI.builder.RegisterModelBinders(typeof(MvcApplication).Assembly);builder.RegisterModelBinderProvider();// OPTIONAL: Register web abstractions like HttpContextBase.builder.RegisterModule<AutofacWebTypesModule>();// OPTIONAL: Enable property injection in view pages.builder.RegisterSource(newViewRegistrationSource());// OPTIONAL: Enable property injection into action filters.builder.RegisterFilterProvider();// OPTIONAL: Enable action method parameter injection (RARE).builder.InjectActionInvoker();// Set the dependency resolver to be Autofac.varcontainer=builder.Build();DependencyResolver.SetResolver(newAutofacDependencyResolver(container));}