コード例 #1
0
ファイル: Startup.cs プロジェクト: hlj671/Surging.GoodDemo
        // public static IContainer AutofacContainer;
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            #region 跨域
            services.AddCors(options =>
                             options.AddPolicy("AllowSameDomain",
                                               bu => bu.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin().AllowCredentials())
                             );


            #endregion
            var factoryContext = new FactoryUnitOfWorkDbContext();
            factoryContext.AddDbContext(services);
            services.AddAutoMapper();
            //依赖注入


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            //将Evolution注册到项目中来,实现依赖注入
            var builder = new ContainerBuilder();
            builder.RegisterModule <DefaultModuleRegister>();
            builder.Populate(services);
            var container = builder.Build();
            return(container.Resolve <IServiceProvider>());
        }
コード例 #2
0
        public IContainer ConfigureServices(ContainerBuilder builder)
        {
            var services       = new ServiceCollection();
            var factoryContext = new FactoryUnitOfWorkDbContext();

            factoryContext.AddDbContext(services);
            services.AddAutoMapper();

            ConfigureLogging(services);
            builder.Populate(services);
            //依赖注入
            builder.RegisterModule <DefaultModuleRegister>();
            ServiceLocator.Current = builder.Build();
            return(ServiceLocator.Current);
        }