示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <DatabaseContext>(options =>
                                                    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")),
                                                    optionsLifetime: ServiceLifetime.Transient
                                                    );

            services.AddCors(options => options.AddPolicy("CorsPolicy",
                                                          builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowCredentials();
            }));


            services.AddMvc();
            services.AddAutoMapper();

            var applicationContainer = DI.AddRegistrationsToDIContainer(services);

            return(new AutofacServiceProvider(applicationContainer));
        }