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

Commit

Permalink
Adding IApplicationLifetime to the manifest
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Praburaj committed Mar 4, 2015
1 parent f2d3458 commit 718d923
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/Microsoft.AspNet.Hosting/HostingServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ private class HostingManifest : IServiceManifest
public HostingManifest(IServiceProvider fallback)
{
var manifest = fallback.GetRequiredService<IServiceManifest>();
Services = new Type[] { typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory), typeof(IHttpContextAccessor) }
.Concat(manifest.Services).Distinct();
Services = new Type[] {
typeof(ITypeActivator),
typeof(IHostingEnvironment),
typeof(ILoggerFactory),
typeof(IHttpContextAccessor),
typeof(IApplicationLifetime)
}.Concat(manifest.Services).Distinct();
}

public IEnumerable<Type> Services { get; private set; }
Expand Down
14 changes: 6 additions & 8 deletions test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using System;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting.Builder;
using Microsoft.AspNet.Hosting.Server;
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.RequestContainer;
using Microsoft.Framework.DependencyInjection;
Expand Down Expand Up @@ -81,22 +79,22 @@ public void EnsureRequestServicesSetsRequestServices(bool initializeApplicationS
}

[Theory]
[InlineData(typeof(IHostingEngine))]
[InlineData(typeof(IServerLoader))]
[InlineData(typeof(IApplicationBuilderFactory))]
[InlineData(typeof(IHttpContextFactory))]
[InlineData(typeof(ITypeActivator))]
[InlineData(typeof(IApplicationLifetime))]
[InlineData(typeof(IHostingEnvironment))]
[InlineData(typeof(ILoggerFactory))]
[InlineData(typeof(IHttpContextAccessor))]
[InlineData(typeof(IApplicationLifetime))]
public void UseRequestServicesHostingImportedServicesAreDefined(Type service)
{
var baseServiceProvider = HostingServices.Create().BuildServiceProvider();
var builder = new ApplicationBuilder(baseServiceProvider);

builder.UseRequestServices();

Assert.NotNull(builder.ApplicationServices.GetRequiredService(service));
var fromAppServices = builder.ApplicationServices.GetRequiredService(service);

Assert.NotNull(fromAppServices);
Assert.Equal(baseServiceProvider.GetRequiredService(service), fromAppServices);
}
}
}

0 comments on commit 718d923

Please sign in to comment.