protected override async void OnStartup(StartupEventArgs e) { base.OnStartup(e); await DbInitialise.Initialise(); _container.RegisterType <IServiceRepository, ServiceRepository>(new ContainerControlledLifetimeManager()); _container.RegisterType <IWatchedServiceRepository, WatchedServiceRepository>(new ContainerControlledLifetimeManager()); _container.RegisterType <IDescriptionService, DescriptionService>(new TransientLifetimeManager()); _container.RegisterType <IStatusService, StatusService>(new TransientLifetimeManager()); UnityBootstrapper.Register(_container); var window = _container.Resolve <MainWindow>(); _trayIcon = Icon.Create(window); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } var prefix = Configuration["SwaggerUrlPrefix"] ?? ""; app.UseSwagger(x => x.PreSerializeFilters.Add((y, z) => { if (!y.Info.Version.Contains("raw")) { var paths = y.Paths.ToList(); y.Paths.Clear(); paths.ForEach(path => y.Paths.Add(prefix + path.Key, path.Value)); } }) ); app.UseSwaggerUI(c => { c.SwaggerEndpoint($"{prefix}/swagger/v{Version}/swagger.json", $"Notification API V{Version}"); }); app.UseHttpsRedirection(); app.UseRouting(); app.UseVersioningEndpoint(); app.UseHealthChecks("/health"); app.UseAuthentication(); app.UseOrganisationSelector(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); using (var initScope = app.ApplicationServices.CreateScope()) { var context = initScope.ServiceProvider.GetService <ApplicationContext>(); DbInitialise.Init(context); } }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <UserDbContext>(); DbInitialise.Initialise(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }