diff --git a/src/Microsoft.AspNetCore.Hosting.Abstractions/HostingAbstractionsWebHostBuilderExtensions.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/HostingAbstractionsWebHostBuilderExtensions.cs
index 31bf39f009..76bb2fec1a 100644
--- a/src/Microsoft.AspNetCore.Hosting.Abstractions/HostingAbstractionsWebHostBuilderExtensions.cs
+++ b/src/Microsoft.AspNetCore.Hosting.Abstractions/HostingAbstractionsWebHostBuilderExtensions.cs
@@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
+using System.Globalization;
using System.Linq;
using System.Threading;
using Microsoft.AspNetCore.Hosting.Server;
@@ -158,6 +159,17 @@ namespace Microsoft.AspNetCore.Hosting
return hostBuilder.UseSetting(WebHostDefaults.PreferHostingUrlsKey, preferHostingUrls ? "true" : "false");
}
+ ///
+ /// Specify the amount of time to wait for the web host to shutdown.
+ ///
+ /// The to configure.
+ /// The amount of time to wait for server shutdown.
+ /// The .
+ public static IWebHostBuilder UseShutdownTimeout(this IWebHostBuilder hostBuilder, TimeSpan timeout)
+ {
+ return hostBuilder.UseSetting(WebHostDefaults.ShutdownTimeoutKey, ((int)timeout.TotalSeconds).ToString(CultureInfo.InvariantCulture));
+ }
+
///
/// Start the web host and listen on the specified urls.
///
diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs
index be0e86c57f..9e33f7822d 100644
--- a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs
+++ b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs
@@ -1036,6 +1036,21 @@ namespace Microsoft.AspNetCore.Hosting
Assert.Throws(() => new HostingStartupAttribute(typeof(WebHostTests)));
}
+ [Fact]
+ public void UseShutdownTimeoutConfiguresShutdownTimeout()
+ {
+ var builder = CreateWebHostBuilder()
+ .CaptureStartupErrors(false)
+ .UseShutdownTimeout(TimeSpan.FromSeconds(102))
+ .Configure(app => { })
+ .UseServer(new TestServer());
+
+ using (var host = (WebHost)builder.Build())
+ {
+ Assert.Equal(TimeSpan.FromSeconds(102), host.Options.ShutdownTimeout);
+ }
+ }
+
private static void StaticConfigureMethod(IApplicationBuilder app) { }
private IWebHostBuilder CreateWebHostBuilder()