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

Commit f080ad2

Browse files
committed
#947 Add IServer.Stop
1 parent 10cdfd9 commit f080ad2

File tree

8 files changed

+55
-2
lines changed

8 files changed

+55
-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
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"OldTypeId": "public interface Microsoft.AspNetCore.Hosting.Server.IServer : System.IDisposable",
4+
"NewTypeId": "public interface Microsoft.AspNetCore.Hosting.Server.IServer : System.IDisposable",
5+
"NewMemberId": "System.Void Stop()",
6+
"Kind": "Addition"
7+
}
8+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"OldTypeId": "public interface Microsoft.AspNetCore.Hosting.Server.IServer : System.IDisposable",
4+
"NewTypeId": "public interface Microsoft.AspNetCore.Hosting.Server.IServer : System.IDisposable",
5+
"NewMemberId": "System.Void Stop()",
6+
"Kind": "Addition"
7+
}
8+
]

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

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

274+
Server?.Stop();
275+
274276
// Fire the IHostedService.Stop
275277
_hostedServiceExecutor?.Stop();
276278

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
@@ -761,6 +761,11 @@ public void Start<TContext>(IHttpApplication<TContext> application)
761761
application.DisposeContext(httpContext, null);
762762
};
763763
}
764+
765+
public void Stop()
766+
{
767+
768+
}
764769
}
765770

766771
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
@@ -761,6 +761,17 @@ public void Start<TContext>(IHttpApplication<TContext> application)
761761
application.DisposeContext(context, null);
762762
}
763763

764+
public void Stop()
765+
{
766+
if (_startInstances != null)
767+
{
768+
foreach (var startInstance in _startInstances)
769+
{
770+
startInstance.Stop();
771+
}
772+
}
773+
}
774+
764775
public void Dispose()
765776
{
766777
if (_startInstances != null)
@@ -813,8 +824,15 @@ public DelegateHostedService(Action started, Action stopping)
813824

814825
private class StartInstance : IDisposable
815826
{
827+
public int StopCalls { get; set; }
828+
816829
public int DisposeCalls { get; set; }
817830

831+
public void Stop()
832+
{
833+
StopCalls += 1;
834+
}
835+
818836
public void Dispose()
819837
{
820838
DisposeCalls += 1;

0 commit comments

Comments
 (0)