protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); MapperInit.Init(); }
public static void RegisterDependencies() { var builder = new ContainerBuilder(); // IMapper builder.Register(c => MapperInit.Init()).AsSelf().SingleInstance(); builder.Register(c => c.Resolve <MapperConfiguration>().CreateMapper(c.Resolve)).As <IMapper>().InstancePerLifetimeScope(); var mapperConfig = new MapperConfiguration(m => { m.AddProfile(new Mappings.Profile.Profile()); }); builder.RegisterInstance(mapperConfig.CreateMapper()) .As <IMapper>() .SingleInstance(); // DbContext builder.RegisterType <VideoClubDbContext>().As <VideoClubDbContext>(); // Controllers builder.RegisterControllers(typeof(MvcApplication).Assembly); // ActionFilters // Services builder.RegisterType <OMDbAPIService>().As <IOMDbAPIService>().InstancePerRequest(); builder.RegisterType <PaginationService>().As <IPaginationService>().InstancePerRequest(); builder.RegisterType <LoggingService>().As <ILoggingService>().InstancePerRequest(); builder.RegisterType <MovieService>().As <IMovieService>().InstancePerRequest(); builder.RegisterType <RentingService>().As <IRentingService>().InstancePerRequest(); builder.RegisterType <CopyService>().As <ICopyService>().InstancePerRequest(); builder.RegisterType <UserService>().As <IUserService>().InstancePerRequest(); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }