Merge branch 'release/2.1' into dev
This commit is contained in:
commit
bfc12fd6ac
|
|
@ -25,8 +25,8 @@ namespace GenericHostSample
|
|||
})
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.AddScoped<IHostedService, MyServiceA>();
|
||||
services.AddScoped<IHostedService, MyServiceB>();
|
||||
services.AddHostedService<MyServiceA>();
|
||||
services.AddHostedService<MyServiceB>();
|
||||
})
|
||||
.Build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ namespace GenericHostSample
|
|||
})
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.AddScoped<IHostedService, MyServiceA>();
|
||||
services.AddScoped<IHostedService, MyServiceB>();
|
||||
services.AddHostedService<MyServiceA>();
|
||||
services.AddHostedService<MyServiceB>();
|
||||
})
|
||||
.Build();
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ namespace GenericHostSample
|
|||
var builder = new HostBuilder()
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.AddScoped<IHostedService, MyServiceA>();
|
||||
services.AddScoped<IHostedService, MyServiceB>();
|
||||
services.AddHostedService<MyServiceA>();
|
||||
services.AddHostedService<MyServiceB>();
|
||||
});
|
||||
|
||||
await builder.RunConsoleAsync();
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ namespace GenericHostSample
|
|||
var builder = new HostBuilder()
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.AddScoped<IHostedService, MyServiceA>();
|
||||
services.AddScoped<IHostedService, MyServiceB>();
|
||||
services.AddHostedService<MyServiceA>();
|
||||
services.AddHostedService<MyServiceB>();
|
||||
});
|
||||
|
||||
await builder.RunAsServiceAsync();
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace GenericWebHost
|
|||
{
|
||||
options.ConfigureApp = configureApp;
|
||||
});
|
||||
services.AddSingleton<IHostedService, WebHostService>();
|
||||
services.AddHostedService<WebHostService>();
|
||||
|
||||
var listener = new DiagnosticListener("Microsoft.AspNetCore");
|
||||
services.AddSingleton<DiagnosticListener>(listener);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
public static class ServiceCollectionHostedServiceExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Add an <see cref="IHostedService"/> registration for the given type.
|
||||
/// </summary>
|
||||
/// <typeparam name="THostedService">An <see cref="IHostedService"/> to register.</typeparam>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/> to register with.</param>
|
||||
/// <returns>The original <see cref="IServiceCollection"/>.</returns>
|
||||
public static IServiceCollection AddHostedService<THostedService>(this IServiceCollection services)
|
||||
where THostedService : class, IHostedService
|
||||
=> services.AddTransient<IHostedService, THostedService>();
|
||||
}
|
||||
}
|
||||
|
|
@ -548,7 +548,7 @@ namespace Microsoft.AspNetCore.Hosting
|
|||
.UseFakeServer()
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
services.AddSingleton<IHostedService, TestHostedService>();
|
||||
services.AddHostedService<TestHostedService>();
|
||||
})
|
||||
.Build())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ namespace Microsoft.Extensions.Hosting
|
|||
using (var host = CreateBuilder()
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.AddSingleton<IHostedService, TestHostedService>();
|
||||
services.AddHostedService<TestHostedService>();
|
||||
})
|
||||
.Build())
|
||||
{
|
||||
|
|
@ -133,7 +133,7 @@ namespace Microsoft.Extensions.Hosting
|
|||
using (var host = CreateBuilder()
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.AddSingleton<IHostedService, TestHostedService>();
|
||||
services.AddHostedService<TestHostedService>();
|
||||
})
|
||||
.Build())
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue