Esempio n. 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              ILoggerFactory loggerFactory, IApplicationLifetime appLifetime)
        {
            /*if (env.IsDevelopment())
             *  app.UseDeveloperExceptionPage();
             * else*/
            app.UseMiddleware <ExceptionHandler>();

            app.UseSerilog(loggerFactory);
            app.UseCors(builder => builder
                        .AllowAnyHeader()
                        .AllowAnyMethod()
                        .AllowAnyOrigin()
                        .AllowCredentials());

            app.UseAuthentication();

            MongoConfigurator.Initialize();

            var generalSettings = app.ApplicationServices.GetService <GeneralSettings>();

            if (generalSettings.SeedData)
            {
                var dataInitializer = app.ApplicationServices.GetService <IDataInitializer>();
                dataInitializer.SeedAsync();
            }

            //app.UseExceptionHandler("/error");
            app.UseMvc();
            appLifetime.ApplicationStopped.Register(() => ApplicationContainer.Dispose());
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime appLifetime,
                              ILoggerFactory loggerFactory)
        {
            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });
            loggerFactory.AddNLog();
            env.ConfigureNLog("nlog.config");

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseMiddleware <TokenManagerMiddleware>();
            app.UseAuthentication();
            app.UseExceptionMiddleware();
            MongoConfigurator.Initialize();
            var generalSettings = app.ApplicationServices.GetService <GeneralSettings>();

            if (generalSettings.DataInitialize)
            {
                var dataInitilizer = app.ApplicationServices.GetService <IDataInitializer>();
                dataInitilizer.SeedAsync();
            }
            app.UseMvc();
            appLifetime.ApplicationStopped.Register(() => ApplicationContainer.Dispose());
        }
Esempio n. 3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            // DATA INITIALIZER (ONLY FOR TESTING AND DEVELOPMENT PURPOSE)
            if (Configuration.GetSettings <GeneralSettings>().SeedData)
            {
                var autofacRoot     = app.ApplicationServices.GetAutofacRoot();
                var dataInitializer = autofacRoot.Resolve <IDataInitializer>();
                dataInitializer.SeedAsync();
            }

            MongoConfigurator.Initialize();
            app.UseRouting();
            app.UseCors(builder => builder
                        .AllowAnyHeader()
                        .AllowAnyMethod()
                        .SetIsOriginAllowed((host) => true)
                        .AllowCredentials()
                        );
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseExceptionMiddleware();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Esempio n. 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime)
        {
            app.UseAuthentication();
            MongoConfigurator.Initialize();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseMiddleware(typeof(ExceptionHandlerMiddleware));
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            ;
            var generalSettings = app.ApplicationServices.GetService <GeneralSettings>();

            if (generalSettings.SeedData)
            {
                var datainitializer = app.ApplicationServices.GetService <IDataInitializer>();
                datainitializer.SeedAsync();
            }
            appLifetime.ApplicationStopped.Register(() => ApplicationContainer.Dispose());
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, Microsoft.AspNetCore.Hosting.IApplicationLifetime applicationLifetime)
        {
            AutofacContainer = app.ApplicationServices.GetAutofacRoot();
            loggerFactory.AddLog4Net();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            var jwtSettings = app.ApplicationServices.GetService <JwtSettings>();

            MongoConfigurator.Initialize();
            Infrastructure.Exceptions.Framework.Extensions.UseExceptionHandler(app);
            var generalSettings = app.ApplicationServices.GetService <GeneralSettings>();

            if (generalSettings.SeedData)
            {
                var dataInitializer = app.ApplicationServices.GetService <IDataInitializer>();
                dataInitializer.SeedAsync();
            }
            app.UseHttpsRedirection();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Esempio n. 6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              ILoggerFactory loggerFactory, IApplicationLifetime appLifeTime)
        {
            // loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            // loggerFactory.AddDebug();

            loggerFactory.AddNLog();
            app.AddNLogWeb();
            env.ConfigureNLog("nlog.config");

            var jwtSettings = app.ApplicationServices.GetService <JwtSettings>();

            app.UseJwtBearerAuthentication(new JwtBearerOptions {
                AutomaticAuthenticate     = true,
                TokenValidationParameters = new TokenValidationParameters {
                    ValidIssuer      = jwtSettings.Issuer,
                    ValidateAudience = false,
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings.Key))
                }
            });

            MongoConfigurator.Initialize();

            var generalSettings = app.ApplicationServices.GetService <GeneralSettings>();

            if (generalSettings.SeedData)
            {
                var dataInitializer = app.ApplicationServices.GetService <IDataInitializer>();
                dataInitializer.SeedAsync();
            }
            app.UseExceptionsHandler();
            app.UseMvc();
            appLifeTime.ApplicationStopped.Register(() => ApplicationContainer.Dispose());
        }
Esempio n. 7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            MongoConfigurator.Initialize();

            var jwtSettings = app.ApplicationServices.GetService <IOptions <JwtSettings> >();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseJwtBearerAuthentication(new JwtBearerOptions
            {
                AutomaticAuthenticate     = true,
                TokenValidationParameters = new TokenValidationParameters
                {
                    ValidIssuer      = jwtSettings.Value.Issuer,
                    ValidateAudience = false,
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings.Value.Key))
                }
            });

            app.UseMvc();
        }
Esempio n. 8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseStaticFiles(new StaticFileOptions()
            {
                OnPrepareResponse = ctx => {
                    ctx.Context.Response.Headers.Append("Access-Control-Allow-Origin", "*");
                    ctx.Context.Response.Headers.Append("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
                },
                FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot")),
                RequestPath  = new PathString("")
            });

            app.UseAuthentication();

            app.UseCors(builder => builder
                        .AllowAnyHeader()
                        .AllowAnyMethod()
                        .AllowAnyOrigin());

            MongoConfigurator.Initialize();

            app.UseImpersonate();
            app.UseMiddleware <ExceptionMiddleware>();
            app.UseMvc();
        }
Esempio n. 9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            ConfigureRabbitMqSubscriptions(app);
            MongoConfigurator.Initialize();
            app.UseMvc();
        }
Esempio n. 10
0
 protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
 {
     base.ApplicationStartup(container, pipelines);
     MongoConfigurator.Initialize();
     SetupTokenAuthentication(container, pipelines);
     pipelines.AfterRequest += (ctx) =>
     {
         AddCorsHeaders(ctx.Response);
     };
     Logger.Information("Lockbox API has started.");
 }
Esempio n. 11
0
        /// <summary>
        /// This method configures the HTTP request pipeline.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        /// <param name="appLifetime"></param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime appLifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            MongoConfigurator.Initialize();

            app.UseMvc();
            appLifetime.ApplicationStopped.Register(() => ApplicationContainer.Dispose());
        }
Esempio n. 12
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime lifeTime)
        {
            //loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            //loggerFactory.AddDebug();
            loggerFactory.AddNLog();
            app.AddNLogWeb();
            env.ConfigureNLog("nlog.config");

            //I can evoke each services which i registered
            var jwtSettings2 = app.ApplicationServices.GetService <jwtSettings>();


            //we use jwtSettings to get our key


            app.UseJwtBearerAuthentication(new Microsoft.AspNetCore.Builder.JwtBearerOptions
            {
                // it uses name/password to properly set ID
                AutomaticAuthenticate     = true,
                TokenValidationParameters = new TokenValidationParameters()
                {
                    //who can issue token
                    //only localhost 5000 can generate token
                    ValidIssuer = jwtSettings2.Issuer,

                    //token can be generated only for specifices domen
                    //here is set-for all
                    ValidateAudience = false,

                    //how key is created/signed
                    //in this case key is from settings of our application
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings2.Key)),
                },
            });
            //Remove  unnecessary dependencies
            lifeTime.ApplicationStopped.Register(() => ApplicationContainer.Dispose());


            MongoConfigurator.Initialize();
            //place where we want to initialzie data
            var genearlSettings = app.ApplicationServices.GetService <GeneralSettings>();

            //checking SeatData flag( true or not)
            if (genearlSettings.SeatData)
            {
                //download IDateInitiazlie from IoC container and evoke Seat method
                var dataInitialzie = app.ApplicationServices.GetService <IDataInitialize>();
                dataInitialzie.Sead();
            }

            app.UseExceptionHandlera();
            NewMethod(app);
        }
Esempio n. 13
0
 public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory,
                       IApplicationLifetime appLifetime)
 {
     MongoConfigurator.Initialize();
     app.UseCors(AllowOrigins);
     app.UseAuthentication();
     app.UseExceptionHandlerMiddleware();
     app.UseMvc();
     app.UseSwagger();
     app.UseSwaggerUI(c => {
         c.SwaggerEndpoint("v1/swagger.json", "gendo-services-templates API v1");
     });
 }
Esempio n. 14
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            SeedData(app);
            app.UseErrorHandler();

            MongoConfigurator.Initialize();

            app.UseAuthentication();
            app.UseMvc();
            appLifetime.ApplicationStopped.Register(() => ApplicationContainer.Dispose());
        }
Esempio n. 15
0
 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime appLifeTime, ILoggerFactory loggerFactory)
 {
     loggerFactory.AddSerilog();
     ConfigureSerilog();
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
     }
     MongoConfigurator.Initialize();
     app.UseCors("AllowAny");
     app.UseAuthentication();
     app.UseMvc();
     app.UseSwagger();
     app.UseSwaggerUI(x => x.SwaggerEndpoint("/swagger/v1/swagger.json", "Hated.Api"));
     appLifeTime.ApplicationStopped.Register(() => ApplicationContainer.Dispose());
 }
Esempio n. 16
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors(policy => { policy.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials(); });

            app.UseAuthentication();

            app.UseStaticFiles();

            MongoConfigurator.Initialize();

            app.UseMvc();
        }
Esempio n. 17
0
 public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory,
                       IApplicationLifetime appLifetime)
 {
     MongoConfigurator.Initialize();
     app.UseCors(AllowOrigins);
     app.UseAuthentication();
     app.UseExceptionHandlerMiddleware();
     app.UseMvc();
     app.UseRabbitMq()
     .SubscribeEvent <TemplateCreated>()
     .SubscribeEvent <TemplateUpdated>()
     .SubscribeEvent <TemplateDeleted>();
     app.UseSwagger();
     app.UseSwaggerUI(c => {
         c.SwaggerEndpoint("v1/swagger.json", "gendo-services-documents API v1");
     });
 }
Esempio n. 18
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime hostApplicationLifetime)
        {
            // if (env.IsDevelopment())
            // {
            //     app.UseDeveloperExceptionPage();
            // }
            MongoConfigurator.Initialize();
            // var dataInitializer = app.ApplicationServices.GetService<IDataInitializer>();
            // dataInitializer.SeedAsync();

            app.UseRouting();
            //app.UseCustomExceptionHandler();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            hostApplicationLifetime.ApplicationStopped.Register(() => ApplicationContainer.Dispose());
        }
Esempio n. 19
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              IApplicationLifetime appLifetime)
        {
            // loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            // loggerFactory.AddDebug();
            loggerFactory.AddNLog();
            env.ConfigureNLog("nlog.config");

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            MongoConfigurator.Initialize();

            SeedData(app);
            app.UseErrorHandler();
            app.UseCors("CorsPolicy");
            app.UseAuthentication();
            appLifetime.ApplicationStopped.Register(() => Container.Dispose());
        }
Esempio n. 20
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime appLifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            MongoConfigurator.Initialize();

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseSpaStaticFiles();

            //app.UseCors(options => options.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials());

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action=Index}/{id?}");
            });

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseReactDevelopmentServer(npmScript: "start");
                }
            });

            appLifetime.ApplicationStopped.Register(() => ApplicationContainer.Dispose());
        }
Esempio n. 21
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IHostApplicationLifetime hostApplicationLifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseMiddleware <ExceptionHandlerMiddleware>();

            app.UseRouting();

            app.UseAuthentication();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            var generalSetting = Configuration.GetSettings <GeneralSettings>();

            if (!generalSetting.InMemoryRepositories)
            {
                MongoConfigurator.Initialize();
            }
            if (generalSetting.SeedData)
            {
                var dataInitializer = app.ApplicationServices.GetService <IDataInitializer>();
                dataInitializer.SeedDefaultAsync();
            }

            hostApplicationLifetime.ApplicationStopped.Register(() =>
                                                                ApplicationContainer.Dispose());
        }
Esempio n. 22
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseSerilog(loggerFactory);

            MongoConfigurator.Initialize();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();

            var scanPageService = app.ApplicationServices.GetService <IScanPageService>();
            var adRepository    = app.ApplicationServices.GetService <IAdRepository>();

            var scrap = JobManager.GetSchedule("Scrap");

            if (scrap == null)
            {
                JobManager.Initialize(new ScrapRegistry(scanPageService, adRepository));
            }
        }
Esempio n. 23
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            MongoConfigurator.Initialize();
            var generalSettings = app.ApplicationServices.GetService <GeneralSettings>();

            if (generalSettings.SeedData)
            {
                var dataInitializer = app.ApplicationServices.GetService <IDataInitializer>();
                dataInitializer.SeedAsync();
            }


            app.UseSession(); //23-03


            app.UseAuthentication();
            app.UseCors(
                options => options.WithOrigins("https://localhost:8080")
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowCredentials()
                );

            app.UseHttpsRedirection(); //
            app.UseHsts();             //

            //         app.UseCors(builder => builder
            // .WithOrigins("http://localhost:8080")
            // .AllowAnyMethod()
            // .AllowAnyHeader()
            // .AllowCredentials()
            // );
            app.UseMvc();
            appLifetime.ApplicationStopped.Register(() => ApplicationContainer.Dispose());
        }
Esempio n. 24
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            // loggerFactory.AddNLog();
            // app.AddNLogWeb();
            // env.ConfigureNLog("nlog.config");

            var jwtSettings = app.ApplicationServices.GetService <JwtSettings>();

            app.UseJwtBearerAuthentication(new JwtBearerOptions
            {
                AutomaticAuthenticate     = true,
                TokenValidationParameters = new TokenValidationParameters
                {
                    ValidIssuer      = jwtSettings.Issuer,                                               //jesli adres aplikacji ktora wygenerowala kod bedzie inny niz ten - blad aplikacji
                    ValidateAudience = false,
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings.Key)) //sposob podpisywania klucza
                }
            });

            MongoConfigurator.Initialize();

            var generalSettings = app.ApplicationServices.GetService <GeneralSettings>();

            if (generalSettings.SeedData)
            {
                var dataInitializer = app.ApplicationServices.GetService <IDataInitializer>();
                dataInitializer.SeedAsync();
            }

            app.UserExceptionHandler();
            app.UseMvc();

            appLifetime.ApplicationStopped.Register(() => ApplicationContainer.Dispose()); //w razie zatrzymania aplikacji, wywola metode register i wywola na kontenerze metode dispose by wyczyscic nieuzytki
        }
Esempio n. 25
0
 public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationEnvironment appEnv,
                       ILoggerFactory loggerFactory, IServiceProvider serviceProvider, GeneralSettings settings)
 {
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
     }
     loggerFactory.AddNLog(Configuration);
     app.UseIISPlatformHandler();
     app.UseStaticFiles();
     app.UseCookieAuthentication(options =>
     {
         options.AutomaticAuthenticate = true;
         options.AutomaticChallenge    = true;
         options.CookieName            = settings.AuthCookieName;
         options.LoginPath             = settings.LoginPath;
         options.LogoutPath            = settings.LogoutPath;
     });
     app.UseSession();
     app.UseMvcWithDefaultRoute();
     MapSignalR(app, serviceProvider);
     MongoConfigurator.Initialize();
     Logger.Info("Application has started.");
 }
Esempio n. 26
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseCors(x => x
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());

            loggerFactory.AddNLog();
            app.AddNLogWeb();
            env.ConfigureNLog("nlog.config");


            MongoConfigurator.Initialize();
            var generalSettings = app.ApplicationServices.GetService <GeneralSettings>();

            if (generalSettings.SeedData)
            {
                var dataInitializer = app.ApplicationServices.GetService <IDataInitializer>();
                dataInitializer.SeedAsync();
            }
            app.UseExceptionHandler2();
            app.UseAuthentication();
            app.UseMvc();
        }
Esempio n. 27
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            AutofacContainer = app.ApplicationServices.GetAutofacRoot();
            MongoConfigurator.Initialize();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            if (bool.Parse(Configuration.GetSection("SeedData").Value))
            {
                var dataSeeder = app.ApplicationServices.GetService <IDataSeeder>();
                dataSeeder.SeedData();
            }

            app.UseMiddleware <ExceptionHandlerMiddleware>();

            app.UseRouting();

            app.UseAuthorization();
            app.UseCors("CorsPolicy");
            app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
        }
Esempio n. 28
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime appLifetime, IServiceProvider serviceProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }
            MongoConfigurator.Initialize();

            var generalSetting = Configuration.GetSettings <GeneralSettings>();

            if (generalSetting.seedData)
            {
                var dataProvider = serviceProvider.GetService <IDataInitializer>();
                dataProvider.SeedAsync();
            }


            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseAuthentication();

            app.UseCors(builder => builder
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());

            app.UseMvc();


            appLifetime.ApplicationStopped.Register(() => ApplicationContainer.Dispose());
        }