public static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Information) .Enrich.FromLogContext() .WriteTo.Debug() .WriteTo.Console() .CreateLogger(); try { Log.Information("Starting hosting"); var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var dbContext = services.GetRequiredService <ApiContext>(); DbGeneratorHelper.Create(services); } host.Run(); } catch (Exception ex) { Log.Fatal(ex, "Host terminated unexpectedly"); } finally { Log.CloseAndFlush(); } }
public ContainerFixture() { var serviceCollection = new ServiceCollection(); serviceCollection .AddApiDependencies() .AddFrameworkDependencies(); ServiceProvider = serviceCollection.BuildServiceProvider(); DbGeneratorHelper.Create(ServiceProvider); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { CurrentEnvironment = env; var forwardingOptions = new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto }; forwardingOptions.KnownNetworks.Clear(); forwardingOptions.KnownProxies.Clear(); app.UseForwardedHeaders(forwardingOptions); app.UseStaticFiles(); app.UseResponseCaching(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseHttpsRedirection(); } else { app.UseExceptionHandler(x => { x.Run(async(context) => { var feature = context.Features.Get <IExceptionHandlerPathFeature>(); var exceptionHelper = new ExceptionLogHelper(); exceptionHelper.LogException(feature.Error, CurrentEnvironment.ContentRootPath); await Task.Run(() => context.Response.Redirect("/views/error.html")); }); }); } app.UseAuthentication(); app.UseMvc(x => { x.MapRoute("default", "{controller=Home}/{action=Index}/{id?}"); }); Container.Install(new SettingAndHelperInstaller()); Container.Install(new FactoryAndMapperInstaller()); Container.Install(new RepositoryAndUnitOfWorkInstaller()); Container.Install(new ServiceInstaller()); DbGeneratorHelper.Generate(Container, env.WebRootPath); }