// 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 applicationLifetime, IOptions <ServiceDisvoveryOptions> serviceOptions, IConsulClient consul) { 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.UseAuthentication(); //app.UseCap(); //启动时候 注册服务 applicationLifetime.ApplicationStarted.Register(() => ResiterService(app, serviceOptions, consul, applicationLifetime)); //todo 停止时 移除服务 applicationLifetime.ApplicationStopped.Register(() => DeRegisterService(app, serviceOptions, consul)); //app.UseHttpsRedirection(); app.UseMvc(); UserContextSeed.SeedAsync(app, loggerFactory).Wait(); }
public LinuxServiceHost( Microsoft.Extensions.Configuration.IConfiguration configuration, Microsoft.Extensions.Hosting.IHostingEnvironment environment, Microsoft.Extensions.Logging.ILogger <LinuxServiceHost> logger, Microsoft.Extensions.Hosting.IApplicationLifetime appLifetime, ICommonService commonService) { this.configuration = configuration; this.logger = logger; this.appLifetime = appLifetime; this.environment = environment; this.commonService = commonService; }
public SmallWebHost(IServiceProvider provider, IConfiguration config, Microsoft.Extensions.Hosting.IApplicationLifetime applicationLifetime, ILogger <SmallWebHost> logger, WebHostOptions options, Action <IApplicationBuilder> appFuncBuilder) { Services = provider; _config = config; _options = options; _logger = logger; _applicationLifetime = applicationLifetime as Microsoft.Extensions.Hosting.Internal.ApplicationLifetime; _appFuncBuilder = appFuncBuilder; }
public void Configure( IApplicationBuilder app, IApplicationLifetime lifetime, IBrowserLauncher browserLauncher, IDirectoryAccessor directoryAccessor, PackageRegistry packageRegistry) { using (var operation = Log.OnEnterAndConfirmOnExit()) { lifetime.ApplicationStopping.Register(() => _disposables.Dispose()); ConfigureForOrchestratorProxy(app); app.Map("/LocalCodeRunner/blazor-console", builder => { builder.UsePathBase("/LocalCodeRunner/blazor-console/"); builder.EnableCachingBlazorContent(); builder.UseBlazor <MLS.Blazor.Program>(); }); var budget = new Budget(); _disposables.Add(() => budget.Cancel()); BlazorPackageConfiguration.Configure(app, app.ApplicationServices, packageRegistry, budget, !StartupOptions.IsLanguageService); app.UseMvc() .UseDefaultFiles() .UseStaticFilesFromToolLocationAndRootDirectory(directoryAccessor.GetFullyQualifiedRoot()); operation.Succeed(); if (StartupOptions.Mode == StartupMode.Try) { var uri = new Uri(app.ServerFeatures.Get <IServerAddressesFeature>().Addresses.First()); Clock.Current .Schedule(_ => LaunchBrowser(browserLauncher, directoryAccessor, uri), TimeSpan.FromSeconds(1)); } } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime lifetime) { app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); // 注册Consul服务 app.RegisterConsul(lifetime, new ServiceEntity { IP = Configuration["Server.Ip.Address"], Port = Convert.ToInt32(Configuration["Service:Port"]), ServiceName = Configuration["Service:Name"], ConsulIP = Configuration["Consul:IP"], ConsulPort = Convert.ToInt32(Configuration["Consul:Port"]) }); app.UseMvc(routes => { routes.MapRoute("default", "{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, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime) { // logging loggerFactory.AddSerilog(); appLifetime.ApplicationStopped.Register(Log.CloseAndFlush); // authentication //app.UseAuthentication(); // in order to be able to log the username, the next step is added after the addition of the authentication middleware app.UseMiddleware <SerilogMiddleware>(); // global exception handling app.UseMiddleware <ExceptionMiddleware>(); // compression app.UseResponseCompression(); // cors app.UseCors(o => { o.AllowAnyHeader() .WithExposedHeaders( "Content-Disposition", "Set-Cookie", ".AspNetCore.Identity.Application", ".AspNetCore.Session", "X-ImportId") //.AllowCredentials() .AllowAnyMethod() .AllowAnyOrigin() .SetIsOriginAllowed(x => true) .SetIsOriginAllowedToAllowWildcardSubdomains(); }); // url rewrite app.ApplyUrlRewrite(); // webapi app.UseMvc(); // enable static files app.UseStaticFiles(); // documentation app.UseSwagger(o => o.RouteTemplate = "docs/{documentName}/swagger.json"); app.UseSwaggerUI(o => { o.RoutePrefix = "docs"; o.SwaggerEndpoint("/docs/v1/swagger.json", "API V1"); }); Log.Logger.Information($"Current build configuration: {Settings.CurrentBuildConfiguration.ToString()}"); }
public GenericWebHostApplicationLifetime(Microsoft.Extensions.Hosting.IApplicationLifetime applicationLifetime) { _applicationLifetime = applicationLifetime; }
/// <summary> /// 注册服务 /// </summary> /// <param name="app"></param> /// <param name="serviceOptions"></param> /// <param name="consul"></param> /// <param name="applicationLifetime"></param> private void ResiterService(IApplicationBuilder app, IOptions <ServiceDisvoveryOptions> serviceOptions, IConsulClient consul, IApplicationLifetime applicationLifetime) { var addresses = GetCurrentUri(app); if (addresses == null) { return; } foreach (var address in addresses) { var serviceId = $"{serviceOptions.Value.ServiceName}_{address.Host}:{address.Port}"; var httpCheck = new AgentServiceCheck() { DeregisterCriticalServiceAfter = TimeSpan.FromMinutes(1), Interval = TimeSpan.FromSeconds(30), HTTP = new Uri(address, "HealthCheck").OriginalString }; var registration = new AgentServiceRegistration() { Checks = new[] { httpCheck }, Address = address.Host, ID = serviceId, Name = serviceOptions.Value.ServiceName, Port = address.Port }; consul.Agent.ServiceRegister(registration).GetAwaiter().GetResult(); } }
public ConsoleLifetime(Microsoft.Extensions.Options.IOptions <Microsoft.Extensions.Hosting.ConsoleLifetimeOptions> options, Microsoft.Extensions.Hosting.IHostingEnvironment environment, Microsoft.Extensions.Hosting.IApplicationLifetime applicationLifetime, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) { }
public ConsoleLifetime(Microsoft.Extensions.Options.IOptions <Microsoft.Extensions.Hosting.ConsoleLifetimeOptions> options, Microsoft.Extensions.Hosting.IHostingEnvironment environment, Microsoft.Extensions.Hosting.IApplicationLifetime applicationLifetime) { }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime appLifetime) { ApplicationContainer = app.ApplicationServices.GetAutofacRoot(); ApplicationContainer.Resolve <IScheduleSettingsCacheService>() .UpdateAllSettingsAsync().GetAwaiter().GetResult(); InitializeJobs(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseCorrelation(); app.UseMiddleware <GlobalErrorHandlerMiddleware>(); app.UseMiddleware <MaintenanceModeMiddleware>(); 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")); appLifetime.ApplicationStopped.Register(() => ApplicationContainer.Dispose()); var application = app.ApplicationServices.GetService <Application>(); appLifetime.ApplicationStarted.Register(() => { var cqrsEngine = ApplicationContainer.Resolve <ICqrsEngine>(); cqrsEngine.StartSubscribers(); cqrsEngine.StartProcesses(); var clientProfileSettingsCache = ApplicationContainer.Resolve <IClientProfileSettingsCache>(); clientProfileSettingsCache.Start(); Program.AppHost.WriteLogs(Environment, LogLocator.CommonLog); LogLocator.CommonLog?.WriteMonitorAsync("", "", $"{Configuration.ServerType()} Started"); }); appLifetime.ApplicationStopping.Register(() => { LogLocator.CommonLog?.WriteMonitorAsync("", "", $"{Configuration.ServerType()} Terminating"); application.StopApplication(); } ); }
public ServiceBaseLifetime(Microsoft.Extensions.Hosting.IHostingEnvironment environment, Microsoft.Extensions.Hosting.IApplicationLifetime applicationLifetime, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) { }
public static void RegisterStopEvent(this Microsoft.Extensions.Hosting.IApplicationLifetime lifeTime, Action callback) => lifeTime.ApplicationStopping.Register(callback);
public GenericWebHostApplicationLifetime(Microsoft.Extensions.Hosting.IApplicationLifetime applicationLifetime) #pragma warning restore CS0618 // Type or member is obsolete { _applicationLifetime = applicationLifetime; }