public static IApplicationBuilder UseWebFramework(this IApplicationBuilder app, WebConfiguration webConfiguration, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } var pathBase = webConfiguration.Configuration["PATH_BASE"]; if (!string.IsNullOrEmpty(pathBase)) { app.UsePathBase(pathBase); } app.UseMiddleware <ErrorHandlingMiddleware>(); app.UseMiddleware <UsernameReceiverMiddleware>(); app.UseHttpsRedirection(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapHealthChecks("/health"); }); if (webConfiguration.WarmupTypes.Any() && !webConfiguration.IsLocal()) { var warmupExecutor = new WarmupTaskExecutor(app.ApplicationServices, webConfiguration); Task.Factory.StartNew(() => warmupExecutor.RunAsync(new CancellationToken())); } return(app); }
public static IServiceCollection AddDbContextUtilities <TDbContext>(this IServiceCollection services, WebConfiguration webConfiguration) where TDbContext : DbContext { services.AddDbContext <TDbContext>(); services.Add <DbContext, TDbContext>(webConfiguration.ServiceLifetime); return(services); }
public static IServiceCollection AddWebFramework(this IServiceCollection services, WebConfiguration webConfiguration) { // Add MVC and Newtonsoft IMvcCoreBuilder mvcBuilder = services .AddMvcCore() .AddApiExplorer() .AddNewtonsoftJson(options => { options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; }); // Add Core Plugins services.AddApplicationServices(webConfiguration); services.AddCorePlugins(webConfiguration); services.AddAutoMapperPlugin(webConfiguration); services.AddAzureBlobStoragePlugin(webConfiguration); services.AddAzureEventGridPlugin(webConfiguration); services.AddEntityFrameworkPlugin(webConfiguration); services.AddFluentValidationPlugin(webConfiguration, mvcBuilder); services.AddMediatRPlugin(webConfiguration); services.AddWarmup(webConfiguration); // Add WebConfiguration and ApplicationContext services.AddSingleton(webConfiguration); // Add Web services services.Add <IJsonSerializer, NewtonsoftJsonSerializer>(webConfiguration.ServiceLifetime); // Add Diagnostics if (webConfiguration.IsAddDiagnostics) { mvcBuilder.PartManager.ApplicationParts.Add(new AssemblyPart(typeof(DiagnosticsController).Assembly)); } return(services); }
public static IServiceCollection AddWebFramework <TDbContext>(this IServiceCollection services, WebConfiguration webConfiguration) where TDbContext : DbContext { services = AddWebFramework(services, webConfiguration); services.AddDbContextUtilities <TDbContext>(webConfiguration); return(services); }