protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); var builder = new ContainerBuilder(); // Get your HttpConfiguration. var config = GlobalConfiguration.Configuration; // Register your Web API controllers. builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); builder.RegisterType <UnitOfWork>().As <IUnitOfWork>(); DIConfiguration.RegisterServices(builder);// builder.RegisterType<StudentService>().As<IStudentService>(); builder.RegisterType <FugaDbcontext>().As <FugaDbcontext>(); builder.RegisterType <FugaContext>().As <FugaContext>(); // OPTIONAL: Register the Autofac filter provider. builder.RegisterWebApiFilterProvider(config); // OPTIONAL: Register the Autofac model binder provider. builder.RegisterWebApiModelBinderProvider(); // Set the dependency resolver to be Autofac. var container = builder.Build(); config.DependencyResolver = new AutofacWebApiDependencyResolver(container); }