// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); var container = new ContainerBuilder(); container.Populate(services); container.RegisterType <PersonQueries>() .As <IPersonQueries>() .InstancePerLifetimeScope(); container.RegisterType <PersonRepository>() .As <IPersonRepository>() .InstancePerLifetimeScope(); container.RegisterType <UnitOfWork>() .As <IUnitOfWork>() .InstancePerLifetimeScope(); container.RegisterModule(new MediatorModule()); #region AutoMapper var dataMapper = new MapperConfiguration(Cfg => { Cfg.AddProfile(new MappingProfile()); }); container.Register(am => dataMapper.CreateMapper()).As <IMapper>(); #endregion return(new AutofacServiceProvider(container.Build())); }
protected void Application_Start() { AutoMapper.Mapper.Initialize(Cfg => Cfg.AddProfile <MapperProfile>()); AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }