Merge branch 'release/2.1' into dev

This commit is contained in:
Chris Ross (ASP.NET) 2018-05-04 14:57:15 -07:00
commit d2857ef02f
1 changed files with 32 additions and 0 deletions

View File

@ -104,6 +104,38 @@ namespace Microsoft.Extensions.Hosting
Assert.Equal(1, service.DisposeCount);
}
[Fact]
public void HostedServiceCanAcceptSingletonDependencies()
{
using (var host = CreateBuilder()
.ConfigureServices((hostContext, services) =>
{
services.AddSingleton<IFakeService, FakeService>();
services.AddHostedService<FakeHostedServiceWithDependency>();
})
.Start())
{
}
}
private class FakeHostedServiceWithDependency : IHostedService
{
public FakeHostedServiceWithDependency(IFakeService fakeService)
{
Assert.NotNull(fakeService);
}
public Task StartAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
[Fact]
public async Task HostedServiceStartNotCalledIfHostNotStarted()
{