protected Server(GracetermOptions gracetermOptions) { LifetimeGracetermService.DisableTerminationFallback = true; var webHostBuilder = new WebHostBuilder() .ConfigureLogging(loggingBuilder => { loggingBuilder.AddDebug(); loggingBuilder.SetMinimumLevel(LogLevel.Trace); }) .Configure(app => { applicationLifetime = app.ApplicationServices.GetService <IHostApplicationLifetime>(); if (applicationLifetime == null) { throw new InvalidOperationException("Could not get IApplicationLifetime service!"); } app.UseGraceterm(); app.Run(async context => { context.Response.StatusCode = 200; await Task.Delay(new Random().Next(10000, 20000)); await context.Response.WriteAsync(ResponseContent); }); }) .ConfigureServices(s => s.AddGraceterm(gracetermOptions)); testServer = new TestServer(webHostBuilder); }
public static IServiceCollection AddGraceterm(this IServiceCollection services, GracetermOptions configureOptions) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (configureOptions is null) { configureOptions = new GracetermOptions(); } services.AddSingleton(configureOptions); return(AddGraceterm(services)); }
public static IServiceCollection AddGraceterm(this IServiceCollection services, Action <GracetermOptions> actionOptions) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (actionOptions is null) { throw new ArgumentNullException(nameof(actionOptions)); } var options = new GracetermOptions(); actionOptions.Invoke(options); return(AddGraceterm(services, options)); }
public static Server Create(GracetermOptions gracetermOptions) { return(new Server(gracetermOptions)); }