Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Commit 543f844

Browse files
committed
#947 Add IServer.Stop
1 parent 39164ee commit 543f844

File tree

8 files changed

+51
-2
lines changed

8 files changed

+51
-2
lines changed

src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,10 @@ public interface IServer : IDisposable
2222
/// <param name="application">An instance of <see cref="IHttpApplication{TContext}"/>.</param>
2323
/// <typeparam name="TContext">The context associated with the application.</typeparam>
2424
void Start<TContext>(IHttpApplication<TContext> application);
25+
26+
/// <summary>
27+
/// Stop processing requests and shut down the server, gracefully if possible.
28+
/// </summary>
29+
void Stop();
2530
}
2631
}

src/Microsoft.AspNetCore.Hosting.Server.Abstractions/exceptions.net45.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@
1010
"NewTypeId": "public interface Microsoft.AspNetCore.Hosting.Server.Features.IServerAddressesFeature",
1111
"NewMemberId": "System.Void set_PreferHostingUrls(System.Boolean value)",
1212
"Kind": "Addition"
13+
},
14+
{
15+
"OldTypeId": "public interface Microsoft.AspNetCore.Hosting.Server.IServer : System.IDisposable",
16+
"NewTypeId": "public interface Microsoft.AspNetCore.Hosting.Server.IServer : System.IDisposable",
17+
"NewMemberId": "System.Void Stop()",
18+
"Kind": "Addition"
1319
}
1420
]

src/Microsoft.AspNetCore.Hosting.Server.Abstractions/exceptions.netcore.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@
1010
"NewTypeId": "public interface Microsoft.AspNetCore.Hosting.Server.Features.IServerAddressesFeature",
1111
"NewMemberId": "System.Void set_PreferHostingUrls(System.Boolean value)",
1212
"Kind": "Addition"
13+
},
14+
{
15+
"OldTypeId": "public interface Microsoft.AspNetCore.Hosting.Server.IServer : System.IDisposable",
16+
"NewTypeId": "public interface Microsoft.AspNetCore.Hosting.Server.IServer : System.IDisposable",
17+
"NewMemberId": "System.Void Stop()",
18+
"Kind": "Addition"
1319
}
1420
]

src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ public void Dispose()
274274
// Fire IApplicationLifetime.Stopping
275275
_applicationLifetime?.StopApplication();
276276

277+
Server?.Stop();
278+
277279
// Fire the IHostedService.Stop
278280
_hostedServiceExecutor?.Stop();
279281

src/Microsoft.AspNetCore.TestHost/TestServer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ void IServer.Start<TContext>(IHttpApplication<TContext> application)
102102
});
103103
}
104104

105+
void IServer.Stop()
106+
{
107+
}
108+
105109
private class ApplicationWrapper<TContext> : IHttpApplication<TContext>
106110
{
107111
private readonly IHttpApplication<TContext> _application;

test/Microsoft.AspNetCore.Hosting.TestSites/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using Microsoft.AspNetCore.Hosting;
5-
using Microsoft.Extensions.Configuration;
6-
using System.Threading;
75
using Microsoft.AspNetCore.Hosting.Server;
86
using Microsoft.AspNetCore.Http.Features;
7+
using Microsoft.Extensions.Configuration;
98

109
namespace ServerComparison.TestSites
1110
{
@@ -39,6 +38,10 @@ public void Dispose()
3938
public void Start<TContext>(IHttpApplication<TContext> application)
4039
{
4140
}
41+
42+
public void Stop()
43+
{
44+
}
4245
}
4346
}
4447

test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,11 @@ public void Start<TContext>(IHttpApplication<TContext> application)
896896
application.DisposeContext(httpContext, null);
897897
};
898898
}
899+
900+
public void Stop()
901+
{
902+
903+
}
899904
}
900905

901906
internal class StartupVerifyServiceA : IStartup

test/Microsoft.AspNetCore.Hosting.Tests/WebHostTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,17 @@ public void Start<TContext>(IHttpApplication<TContext> application)
819819
application.DisposeContext(context, null);
820820
}
821821

822+
public void Stop()
823+
{
824+
if (_startInstances != null)
825+
{
826+
foreach (var startInstance in _startInstances)
827+
{
828+
startInstance.Stop();
829+
}
830+
}
831+
}
832+
822833
public void Dispose()
823834
{
824835
if (_startInstances != null)
@@ -871,8 +882,15 @@ public DelegateHostedService(Action started, Action stopping)
871882

872883
private class StartInstance : IDisposable
873884
{
885+
public int StopCalls { get; set; }
886+
874887
public int DisposeCalls { get; set; }
875888

889+
public void Stop()
890+
{
891+
StopCalls += 1;
892+
}
893+
876894
public void Dispose()
877895
{
878896
DisposeCalls += 1;

0 commit comments

Comments
 (0)