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.
This commit is contained in:
parent
f2d345855b
commit
718d923c7d
|
|
@ -45,8 +45,13 @@ namespace Microsoft.AspNet.Hosting
|
||||||
public HostingManifest(IServiceProvider fallback)
|
public HostingManifest(IServiceProvider fallback)
|
||||||
{
|
{
|
||||||
var manifest = fallback.GetRequiredService<IServiceManifest>();
|
var manifest = fallback.GetRequiredService<IServiceManifest>();
|
||||||
Services = new Type[] { typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory), typeof(IHttpContextAccessor) }
|
Services = new Type[] {
|
||||||
.Concat(manifest.Services).Distinct();
|
typeof(ITypeActivator),
|
||||||
|
typeof(IHostingEnvironment),
|
||||||
|
typeof(ILoggerFactory),
|
||||||
|
typeof(IHttpContextAccessor),
|
||||||
|
typeof(IApplicationLifetime)
|
||||||
|
}.Concat(manifest.Services).Distinct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Type> Services { get; private set; }
|
public IEnumerable<Type> Services { get; private set; }
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
using Microsoft.AspNet.Hosting.Builder;
|
|
||||||
using Microsoft.AspNet.Hosting.Server;
|
|
||||||
using Microsoft.AspNet.Http.Core;
|
using Microsoft.AspNet.Http.Core;
|
||||||
using Microsoft.AspNet.RequestContainer;
|
using Microsoft.AspNet.RequestContainer;
|
||||||
using Microsoft.Framework.DependencyInjection;
|
using Microsoft.Framework.DependencyInjection;
|
||||||
|
|
@ -81,14 +79,11 @@ namespace Microsoft.AspNet.Hosting.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(typeof(IHostingEngine))]
|
|
||||||
[InlineData(typeof(IServerLoader))]
|
|
||||||
[InlineData(typeof(IApplicationBuilderFactory))]
|
|
||||||
[InlineData(typeof(IHttpContextFactory))]
|
|
||||||
[InlineData(typeof(ITypeActivator))]
|
[InlineData(typeof(ITypeActivator))]
|
||||||
[InlineData(typeof(IApplicationLifetime))]
|
[InlineData(typeof(IHostingEnvironment))]
|
||||||
[InlineData(typeof(ILoggerFactory))]
|
[InlineData(typeof(ILoggerFactory))]
|
||||||
[InlineData(typeof(IHttpContextAccessor))]
|
[InlineData(typeof(IHttpContextAccessor))]
|
||||||
|
[InlineData(typeof(IApplicationLifetime))]
|
||||||
public void UseRequestServicesHostingImportedServicesAreDefined(Type service)
|
public void UseRequestServicesHostingImportedServicesAreDefined(Type service)
|
||||||
{
|
{
|
||||||
var baseServiceProvider = HostingServices.Create().BuildServiceProvider();
|
var baseServiceProvider = HostingServices.Create().BuildServiceProvider();
|
||||||
|
|
@ -96,7 +91,10 @@ namespace Microsoft.AspNet.Hosting.Tests
|
||||||
|
|
||||||
builder.UseRequestServices();
|
builder.UseRequestServices();
|
||||||
|
|
||||||
Assert.NotNull(builder.ApplicationServices.GetRequiredService(service));
|
var fromAppServices = builder.ApplicationServices.GetRequiredService(service);
|
||||||
|
|
||||||
|
Assert.NotNull(fromAppServices);
|
||||||
|
Assert.Equal(baseServiceProvider.GetRequiredService(service), fromAppServices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue