// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public async void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env, IServiceProvider serviceProvider, IApplicationLifetime lifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRouteAnalyzer("/routes"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "AnonPatients", template: "Anonymous/Patients/{action}/{id?}" ); }); await CreateRoles(app); await CreateAnonymousRole(app); await CreateReportingRole(app); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env, ILoggerFactory loggerFactory, Microsoft.AspNetCore.Hosting.IApplicationLifetime appLifetime) { // loggerFactory.AddConsole(Configuration.GetSection("Logging")); // loggerFactory.AddDebug(); loggerFactory.AddNLog(); app.AddNLogWeb(); env.ConfigureNLog("nlog.config"); var jwtSettings = app.ApplicationServices.GetService <IOptions <JwtSettings> >(); app.UseJwtBearerAuthentication(new JwtBearerOptions { AutomaticAuthenticate = true, TokenValidationParameters = new TokenValidationParameters { ValidIssuer = jwtSettings.Value.Issuer, ValidateAudience = false, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings.Value.Key)) } }); SeedData(app); app.UseErrorHandler(); app.UseMvc(); appLifetime.ApplicationStopped.Register(() => Container.Dispose()); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IApplicationLifetime lifetime, IHostingEnvironment env) { var quartz = app.ApplicationServices.GetRequiredService <QuartzStartup>(); lifetime.ApplicationStarted.Register(quartz.Start); lifetime.ApplicationStopped.Register(quartz.Stop); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseCookiePolicy(); app.UseCrystalQuartz(() => quartz.Scheduler); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApplicationLifetime lifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } lifetime.ApplicationStarted.Register(() => { // start Akka.NET app.ApplicationServices.GetService <ActorSystem>(); }); lifetime.ApplicationStopping.Register(() => { // stop Akka.NET app.ApplicationServices.GetService <ActorSystem>().Terminate().Wait(); }); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApplicationLifetime lifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); lifetime.ApplicationStarted.Register(new WorkPreparator(Configuration.GetConnectionString("connectingString")).createJourneysAndCashAmount); lifetime.ApplicationStarted.Register(new WorkEnder(Configuration.GetConnectionString("connectingString")).collectTransactions); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApplicationLifetime applicationLifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseWebAssemblyDebugging(); } else { app.UseExceptionHandler("/Error"); } app.UseBlazorFrameworkFiles(); app.UseStaticFiles(); app.UseRouting(); //add Authentication and Authorization app.UseAuthentication(); app.UseAuthorization(); applicationLifetime.ApplicationStopping.Register(OnShutdown); // app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); endpoints.MapControllers(); endpoints.MapFallbackToFile("index.html"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Microsoft.AspNetCore.Hosting.IApplicationLifetime applicationLifetime, IConsulClient client) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.UseRabbitMq() .SubscribeEvent <CreateOrderEvent>(@namespace: "Orders"); var consulServiceId = app.UseConsul(); applicationLifetime.ApplicationStopped.Register(() => { client.Agent.ServiceDeregister(consulServiceId); Container.Dispose(); }); applicationLifetime.ApplicationStopped.Register(() => { Container.Dispose(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Microsoft.AspNetCore.Hosting.IApplicationLifetime lifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Let's Write Together V1"); c.RoutePrefix = string.Empty; }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); lifetime.ApplicationStopping.Register(Stopping); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure( IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime applicationLifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseStaticFiles(); app.UseCookiePolicy(); //var bus = Register(); //start / stop the bus with the web application //applicationLifetime.ApplicationStarted.Register(bus.Start); //applicationLifetime.ApplicationStopped.Register(bus.Stop); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Microsoft.AspNetCore.Hosting.IApplicationLifetime applicationLifetime, IOptions <ServiceDisvoveryOptions> serviceOptions, IConsulClient consul, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //Æô¶¯ applicationLifetime.ApplicationStarted.Register(() => { RegisterService(app, serviceOptions, consul); }); //Í£Ö¹ applicationLifetime.ApplicationStopped.Register(() => { DeRegisterService(app, serviceOptions, consul); }); app.UseRouting(); app.UseAuthorization(); app.UseAuthentication(); RegisterZipkinTrace(app, loggerFactory, applicationLifetime); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Microsoft.AspNetCore.Hosting.IApplicationLifetime lifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors("CustomCorsPolicy"); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); ////服务注册 //ConsulConfig.ConsulRegist.RegistConsul().Wait(); ////服务注销 //ConsulConfig.ConsulRegist.DesregisterConsul(lifetime); //服务注册 ZHYYSservicesCommon.ConsulConfig.ConsulRegist consul = new ZHYYSservicesCommon.ConsulConfig.ConsulRegist(root); consul.RegistConsul().Wait(); //服务注销 consul.DesregisterConsul(lifetime); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Microsoft.AspNetCore.Hosting.IApplicationLifetime applicationLifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseTenantMiddleware(); app.UseRabbitMq("tenant1") .SubscribeEvent <UpdateStockEvent>(); app.UseRabbitMq("tenant2") .SubscribeEvent <UpdateStockEvent>(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); applicationLifetime.ApplicationStopped.Register(() => { Container.Dispose(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IServiceProvider provider, IHostingEnvironment env, IApplicationLifetime lifetime, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseMvc(); var consulConfig = provider.GetService <ConsulConfig>(); var consulClient = provider.GetService <IConsulClient>(); var logger = loggerFactory.CreateLogger <Startup>(); app.RegisterConsul(consulConfig, consulClient, lifetime, logger); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApplicationLifetime lifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); } app.UseStaticFiles(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapBlazorHub(); endpoints.MapFallbackToPage("/_Host"); }); lifetime.ApplicationStarted.Register(() => { var actorName = "countActor"; AkkaLoad.RegisterActor(actorName, actorSystem.ActorOf(Props.Create(() => new CountActor()), actorName)); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApplicationLifetime lifetime) { this.env = env; if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } lifetime.ApplicationStopped.Register(OnAppStopped); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Microsoft.AspNetCore.Hosting.IApplicationLifetime lifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); ConsulEntity consulEntity = new ConsulEntity { Ip = Configuration["Ip"], Port = int.Parse(Configuration["Port"]), ServiceName = Configuration["Service:Name"], ConsulIp = Configuration["Consul:Ip"], ConsulPort = Convert.ToInt32(Configuration["Consul:Port"]) }; app.UseConsul(lifetime, consulEntity); }
public void Configure(IApplicationBuilder app, IApplicationLifetime applicationLifetime, AspNetCore.Hosting.IHostingEnvironment env, ILoggerFactory loggerFactory) { // This middleware is only added when env.IsLinuxConsumption() // It should be a no-op for most tests app.UseMiddleware <AppServiceHeaderFixupMiddleware>(); _startup.Configure(app, applicationLifetime, env, loggerFactory); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApplicationLifetime applicationLifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); var url = Configuration["urls"]; var ipStart = url.IndexOf("http://") + 7; var ipEnd = url.LastIndexOf(":"); var ipLength = ipEnd - ipStart; var ip = url.Substring(ipStart, ipLength); var port = url.Substring(ipEnd + 1); var serviceName = "DatabaseService"; var serviceId = serviceName + Guid.NewGuid(); //注册服务到Consul using (var consulClient = new ConsulClient(ConsulConfig)) { var registration = new AgentServiceRegistration(); //服务提供方的ip和端口 registration.Address = ip; registration.Port = Convert.ToInt32(port); //服务编号 registration.ID = serviceId; //服务名称 registration.Name = serviceName; //健康检查地址 registration.Check = new AgentServiceCheck() { //服务停止多久后注销 DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(5), //健康检查地址 HTTP = $"http://{ip}:{port}/WeatherForecast", //心跳间隔时间 Interval = TimeSpan.FromSeconds(10), //请求超时时间 Timeout = TimeSpan.FromSeconds(5) }; consulClient.Agent.ServiceRegister(registration).Wait(); } applicationLifetime.ApplicationStopped.Register(() => { using (var consulClient = new ConsulClient(ConsulConfig)) { Console.WriteLine($"服务注销, time : {DateTime.Now}"); consulClient.Agent.ServiceDeregister(serviceId).Wait(); } }); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime applicationLifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //app.UseBlockingDetection(); //errors app.UseException(); app.UseRouting(); // Monitor var monitorOptions = Configuration.GetSection("Monitor").Get <MonitorOptions>(); if (monitorOptions.UseMonitor) { app.UseHttpLog(); } app.UseCors("AllowAllPolicy"); app.UseAuthentication(); app.UseAuthorization(); app.UseDefaultFiles(); app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"App_Data")), RequestPath = new PathString("/StaticFiles") }); app.UseWebSockets(); var useHttps = Configuration.GetValue <bool?>("UseHttps"); if (useHttps.HasValue && useHttps.Value) { app.UseHttpsRedirection(); } app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapHealthChecks("/health", new HealthCheckOptions() { Predicate = _ => true, ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); endpoints.MapHub <AgentHub>("/hubs/agent"); endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); endpoints.MapDefaultControllerRoute(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime applicationLifeTime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); applicationLifeTime.ApplicationStopped.Register(() => Container.Dispose()); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime appLifetime) { try { ApplicationContainer = app.ApplicationServices.GetAutofacRoot(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseLykkeForwardedHeaders(); app.UseCorrelation(); #if DEBUG app.UseLykkeMiddleware(ServiceName, ex => ex.ToString()); #else app.UseLykkeMiddleware(ServiceName, ex => new ErrorResponse { ErrorMessage = ex.Message }); #endif app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.UseSwagger(c => { c.PreSerializeFilters.Add((swagger, httpReq) => swagger.Servers = new List <OpenApiServer> { new OpenApiServer { Url = $"{httpReq.Scheme}://{httpReq.Host.Value}" } }); }); app.UseSwaggerUI(a => a.SwaggerEndpoint("/swagger/v1/swagger.json", "Trading Engine API Swagger")); app.UseStaticFiles(); appLifetime.ApplicationStarted.Register(() => StartApplication().GetAwaiter().GetResult()); appLifetime.ApplicationStopping.Register(() => StopApplication().GetAwaiter().GetResult()); appLifetime.ApplicationStopped.Register(() => CleanUp().GetAwaiter().GetResult()); } catch (Exception ex) { Log?.WriteFatalError(nameof(Startup), nameof(Configure), ex); throw; } }
public NBXplorerListener(ExplorerClientProvider explorerClients, BTCPayWalletProvider wallets, InvoiceRepository invoiceRepository, EventAggregator aggregator, IHostApplicationLifetime lifetime) { PollInterval = TimeSpan.FromMinutes(1.0); _Wallets = wallets; _InvoiceRepository = invoiceRepository; _ExplorerClients = explorerClients; _Aggregator = aggregator; _Lifetime = lifetime; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure( IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime lifetime ) { // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Api v1"); }); // global cors policy app.UseCors(x => x .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseAuthentication(); app.UseMiddleware <TokenMiddleware>(); app.UseMvc(); app.UseHttpsRedirection(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); lifetime.ApplicationStarted.Register(() => { app.ApplicationServices.GetService <ActorSystem>(); // start Akka.NET }); lifetime.ApplicationStopping.Register(() => { app.ApplicationServices.GetService <ActorSystem>()?.Terminate().Wait(); }); var logger = loggerFactory.CreateLogger("LoggerInStartup"); logger.LogInformation($"\n\n{DateTime.Now} | Startup logger was launched"); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime applicationLifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); app.ConfigureSwagger(); GetBindingHostedService.ServerAddresses = app.ServerFeatures.Get <IServerAddressesFeature>(); applicationLifetime.ApplicationStarted.Register(Program.Run); }
// 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, IServiceProvider serviceProvider) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } loggerFactory.AddLog4Net(); // auth app.UseAuthentication(); // app.RegisterWithConsul(lifetime, serviceProvider); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); #region register this service //ConsulService consulService = new ConsulService() //{ // IP = Configuration["Consul:IP"], // Port = Convert.ToInt32(Configuration["Consul:Port"]) //}; //HealthService healthService = new HealthService() //{ // IP = Configuration["Service:IP"], // Port = Convert.ToInt32(Configuration["Service:Port"]), // Name = Configuration["Service:Name"], //}; //app.RegisterConsul(lifetime, healthService, consulService); #endregion }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Microsoft.AspNetCore.Hosting.IApplicationLifetime applicationLifetime) { app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Slip Stream-API")); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); } app.UseStaticFiles(); if (!env.IsDevelopment()) { app.UseSpaStaticFiles(); } app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller}/{action=Index}/{id?}"); }); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); applicationLifetime.ApplicationStopped.Register(() => { ClusterHelper.Close(); }); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Microsoft.AspNetCore.Hosting.IApplicationLifetime applicationLifetime, IRouteAnalyzer routeAnalyzer) { app.UseRouting(); // global cors policy app.UseCors(x => x .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. /// <summary> /// 配置方法 /// </summary> /// <param name="app"></param> /// <param name="env"></param> /// <param name="appLifetime"></param> public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApplicationLifetime appLifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "HubRestful v1")); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseWebSockets(new WebSocketOptions() { KeepAliveInterval = TimeSpan.FromSeconds(120), ReceiveBufferSize = 4 * 1024 }); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); //从容器中申请单例 var quartz = app.ApplicationServices.GetRequiredService <QuartzStartup>(); var quote = app.ApplicationServices.GetRequiredService <QuoteUdpStartup>(); var opc = app.ApplicationServices.GetRequiredService <OpcClient>(); appLifetime.ApplicationStarted.Register(() => { // quartz.Start().Wait(); //网站启动完成执行 quote.Start().Wait(); // opc.Start().Wait(); }); appLifetime.ApplicationStopped.Register(() => { // quartz.Stop(); //网站停止完成执行 quote.Stop(); // opc.Stop(); }); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Microsoft.AspNetCore.Hosting.IApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseAuthorization(); applicationLifetime.ApplicationStarted.Register(OnApplicationStarted); applicationLifetime.ApplicationStopping.Register(OnApplicationStopping); applicationLifetime.ApplicationStopped.Register(OnApplicationStopped); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApplicationLifetime applicationLifetime, IMemeRepository memeRepository) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } FleckServer.Start(socket => { var cancToken = new CancellationTokenSource(); var Task = new FleckTask(socket, cancToken.Token, memeRepository); socket.OnOpen = () => Task.Start(); socket.OnClose = () => cancToken.Cancel(); }); applicationLifetime.ApplicationStopping.Register(() => { FleckServer.Dispose(); List <Task> workingMemes = new List <Task>( from meme in memeRepository.Memes where meme.MemeWork.Status == WorkStatus.Working select meme.MemeWork.Worker); Task.WhenAll(workingMemes).Wait(); }); app.UseRouting(); app.UseSpaStaticFiles(); app.UseCors("CorsPolicy"); //app.UseHttpsRedirection(); app.UseEndpoints(endpoints => endpoints.MapControllers()); app.UseSpa(spa => { spa.Options.SourcePath = env.IsDevelopment() ? "catvibing/" : "dist"; if (env.IsDevelopment()) { spa.UseVueCli(npmScript: "serve"); } }); }