private void ValidateConfiguration() { var validationOutcomes = RuntimeValidator.Run(Configuration); if (validationOutcomes.Any(validationOutcome => validationOutcome.Successful == false)) { throw new Exception("Unable to start up due to invalid configuration"); } }
public static IWebHost ValidateSetup(this IWebHost webHost) { Guard.NotNull(webHost, nameof(webHost)); var runtimeValidator = new RuntimeValidator(); runtimeValidator.Run(); return(webHost); }
public void Configure(IApplicationBuilder app) { try { foreach (JsonConfigurationProvider jscp in ((IConfigurationRoot)this.Configuration).Providers.OfType <JsonConfigurationProvider>()) { StaticLogger.Log($"Configuration Loaded: {jscp.Source.Path}", StaticLogger.LoggingLevel.Call); } app.UseSession(); //app.UseHttpsRedirection(); app.UseStaticFiles(); //app.UseStaticFiles(new StaticFileOptions() //{ // ServeUnknownFileTypes = true //}); app.UseCookiePolicy(); app.UseWhen(context => PersistenceConfigured, appBuilder => { appBuilder.UseMiddleware <ServiceScope>(); foreach (Type t in TypeFactory.GetAllImplementations(typeof(IPenguinMiddleware))) { MethodInfo m = typeof(UseMiddlewareExtensions).GetMethods() .First(mi => mi.Name == nameof(UseMiddlewareExtensions.UseMiddleware) && !mi.ContainsGenericParameters ); m.Invoke(null, new object[] { appBuilder, t, Array.Empty <object>() }); } appBuilder.UseMiddleware <ExceptionHandling>(); }); app.UseWhen(context => !PersistenceConfigured, appBuilder => { appBuilder.UseMiddleware <ConfigurePersistenceMiddleware>(); }); IProvideConfigurations provideConnectionStrings = new ConfigurationProviderList( new JsonProvider(this.Configuration) ); DependencyEngine.Register((serviceProvider) => { return(provideConnectionStrings); }); foreach (Type t in TypeFactory.GetAllImplementations(typeof(IRouteConfig))) { if (Activator.CreateInstance(t) is IRouteConfig r) { app.UseMvc(r.RegisterRoutes); } else { throw new Exception("Somehow we managed to initialize a null route configuration"); } } app.UseMvc(routes => { routes.MapRoute( name: "areaRoute", template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}" ); }); #if DEBUG RuntimeValidator.ExecuteTests(); #endif MessageBus.SubscribeAll(); try { ConfigureDatabase(); } catch (Exception cex) { Exceptions.Add(new StartupException(cex)); PersistenceConfigured = false; } StaticLogger.Log($"Application initialization completed.", StaticLogger.LoggingLevel.Final); } catch (Exception ex) { Exceptions.Add(new StartupException(ex)); throw; } }