Example #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 <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")),
                                                         optionsLifetime: ServiceLifetime.Transient
                                                         );

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

            ConfigureAuthentication(services);

            services.AddMvc()
            .AddJsonOptions(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

            services.AddAutoMapper();

            var applicationContainer = Bootstrapper.AddRegistrationsToDIContainer(services);

            return(new AutofacServiceProvider(applicationContainer));
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))
                                                         );

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

            ConfigureAuthentication(services);

            services.AddMvc();

            var applicationContainer = Bootstrapper.AddRegistrationsToDIContainer(services);

            return(new AutofacServiceProvider(applicationContainer));
        }