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

Commit 718d923

Browse files
author
Praburaj
committed
Adding IApplicationLifetime to the manifest
Since IApplicationLifetime is not added to the manifest, while calling HostingServices.Create() before invoking ConfigureServices() we end up creating a new instance of IApplicationLifetime. So the Cancellationtoken that hosting triggers on appshutdown is different from what the app is exposed.
1 parent f2d3458 commit 718d923

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/Microsoft.AspNet.Hosting/HostingServices.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ private class HostingManifest : IServiceManifest
4545
public HostingManifest(IServiceProvider fallback)
4646
{
4747
var manifest = fallback.GetRequiredService<IServiceManifest>();
48-
Services = new Type[] { typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory), typeof(IHttpContextAccessor) }
49-
.Concat(manifest.Services).Distinct();
48+
Services = new Type[] {
49+
typeof(ITypeActivator),
50+
typeof(IHostingEnvironment),
51+
typeof(ILoggerFactory),
52+
typeof(IHttpContextAccessor),
53+
typeof(IApplicationLifetime)
54+
}.Concat(manifest.Services).Distinct();
5055
}
5156

5257
public IEnumerable<Type> Services { get; private set; }

test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
using System;
55
using Microsoft.AspNet.Builder;
6-
using Microsoft.AspNet.Hosting.Builder;
7-
using Microsoft.AspNet.Hosting.Server;
86
using Microsoft.AspNet.Http.Core;
97
using Microsoft.AspNet.RequestContainer;
108
using Microsoft.Framework.DependencyInjection;
@@ -81,22 +79,22 @@ public void EnsureRequestServicesSetsRequestServices(bool initializeApplicationS
8179
}
8280

8381
[Theory]
84-
[InlineData(typeof(IHostingEngine))]
85-
[InlineData(typeof(IServerLoader))]
86-
[InlineData(typeof(IApplicationBuilderFactory))]
87-
[InlineData(typeof(IHttpContextFactory))]
8882
[InlineData(typeof(ITypeActivator))]
89-
[InlineData(typeof(IApplicationLifetime))]
83+
[InlineData(typeof(IHostingEnvironment))]
9084
[InlineData(typeof(ILoggerFactory))]
9185
[InlineData(typeof(IHttpContextAccessor))]
86+
[InlineData(typeof(IApplicationLifetime))]
9287
public void UseRequestServicesHostingImportedServicesAreDefined(Type service)
9388
{
9489
var baseServiceProvider = HostingServices.Create().BuildServiceProvider();
9590
var builder = new ApplicationBuilder(baseServiceProvider);
9691

9792
builder.UseRequestServices();
9893

99-
Assert.NotNull(builder.ApplicationServices.GetRequiredService(service));
94+
var fromAppServices = builder.ApplicationServices.GetRequiredService(service);
95+
96+
Assert.NotNull(fromAppServices);
97+
Assert.Equal(baseServiceProvider.GetRequiredService(service), fromAppServices);
10098
}
10199
}
102100
}

0 commit comments

Comments
 (0)