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