Clean up IApplicaitonLifetime service injection.
This commit is contained in:
parent
43ae61f7bc
commit
25db412332
|
|
@ -27,7 +27,6 @@ namespace Microsoft.AspNet.Hosting
|
||||||
{
|
{
|
||||||
public IServiceProvider Services { get; set; }
|
public IServiceProvider Services { get; set; }
|
||||||
public IConfiguration Configuration { get; set; }
|
public IConfiguration Configuration { get; set; }
|
||||||
public ApplicationLifetime Lifetime { get; set; }
|
|
||||||
|
|
||||||
public IBuilder Builder { get; set; }
|
public IBuilder Builder { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,35 +46,24 @@ namespace Microsoft.AspNet.Hosting
|
||||||
|
|
||||||
public IDisposable Start(HostingContext context)
|
public IDisposable Start(HostingContext context)
|
||||||
{
|
{
|
||||||
EnsureLifetime(context);
|
|
||||||
EnsureBuilder(context);
|
EnsureBuilder(context);
|
||||||
EnsureServerFactory(context);
|
EnsureServerFactory(context);
|
||||||
InitalizeServerFactory(context);
|
InitalizeServerFactory(context);
|
||||||
EnsureApplicationDelegate(context);
|
EnsureApplicationDelegate(context);
|
||||||
|
|
||||||
|
var applicationLifetime = (ApplicationLifetime)context.Services.GetService<IApplicationLifetime>();
|
||||||
var pipeline = new PipelineInstance(_httpContextFactory, context.ApplicationDelegate);
|
var pipeline = new PipelineInstance(_httpContextFactory, context.ApplicationDelegate);
|
||||||
var server = context.ServerFactory.Start(context.Server, pipeline.Invoke);
|
var server = context.ServerFactory.Start(context.Server, pipeline.Invoke);
|
||||||
|
|
||||||
return new Disposable(() =>
|
return new Disposable(() =>
|
||||||
{
|
{
|
||||||
context.Lifetime.SignalStopping();
|
applicationLifetime.SignalStopping();
|
||||||
server.Dispose();
|
server.Dispose();
|
||||||
context.Lifetime.SignalStopped();
|
|
||||||
pipeline.Dispose();
|
pipeline.Dispose();
|
||||||
|
applicationLifetime.SignalStopped();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EnsureLifetime(HostingContext context)
|
|
||||||
{
|
|
||||||
if (context.Lifetime == null)
|
|
||||||
{
|
|
||||||
context.Lifetime = new ApplicationLifetime();
|
|
||||||
}
|
|
||||||
var serviceCollection = new ServiceCollection();
|
|
||||||
serviceCollection.AddInstance<IApplicationLifetime>(context.Lifetime);
|
|
||||||
context.Services = serviceCollection.BuildServiceProvider(context.Services);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void EnsureBuilder(HostingContext context)
|
private void EnsureBuilder(HostingContext context)
|
||||||
{
|
{
|
||||||
if (context.Builder != null)
|
if (context.Builder != null)
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,8 @@ namespace Microsoft.AspNet.Hosting
|
||||||
|
|
||||||
yield return describer.Transient<ITypeActivator, TypeActivator>();
|
yield return describer.Transient<ITypeActivator, TypeActivator>();
|
||||||
|
|
||||||
|
yield return describer.Instance<IApplicationLifetime>(new ApplicationLifetime());
|
||||||
|
|
||||||
// TODO: We expect this to be provide by the runtime eventually.
|
// TODO: We expect this to be provide by the runtime eventually.
|
||||||
yield return describer.Instance<ILoggerFactory>(new NullLoggerFactory());
|
yield return describer.Instance<ILoggerFactory>(new NullLoggerFactory());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Hosting
|
||||||
shutdownHandle.Set();
|
shutdownHandle.Set();
|
||||||
});
|
});
|
||||||
|
|
||||||
Task ignored = Task.Run(() =>
|
var ignored = Task.Run(() =>
|
||||||
{
|
{
|
||||||
Console.WriteLine("Started");
|
Console.WriteLine("Started");
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue