ServiceCollectionHostedServiceExtensions.AddHostedService メソッド

定義

オーバーロード

AddHostedService<THostedService>(IServiceCollection)

指定した型の IHostedService の登録を追加します。

AddHostedService<THostedService>(IServiceCollection, Func<IServiceProvider,THostedService>)

指定した型の IHostedService の登録を追加します。

AddHostedService<THostedService>(IServiceCollection)

ソース:
ServiceCollectionHostedServiceExtensions.cs
ソース:
ServiceCollectionHostedServiceExtensions.cs
ソース:
ServiceCollectionHostedServiceExtensions.cs

指定した型の IHostedService の登録を追加します。

public:
generic <typename THostedService>
 where THostedService : class, Microsoft::Extensions::Hosting::IHostedService[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddHostedService(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddHostedService<THostedService> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services) where THostedService : class, Microsoft.Extensions.Hosting.IHostedService;
static member AddHostedService : Microsoft.Extensions.DependencyInjection.IServiceCollection -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'HostedService : null and 'HostedService :> Microsoft.Extensions.Hosting.IHostedService)
<Extension()>
Public Function AddHostedService(Of THostedService As {Class, IHostedService}) (services As IServiceCollection) As IServiceCollection

型パラメーター

THostedService

IHostedService登録する 。

パラメーター

services
IServiceCollection

登録する先の IServiceCollection

戻り値

元の IServiceCollection

注釈

注意

同じクラスに対してこのメソッドを複数回呼び出さないでください。 これを行うと、指定した最初の HostedService のみが登録されます。 複数の HostedServices を追加するには、 の実装IHostedServiceごとに を明示的に使用AddSingleton<TService>(IServiceCollection)します。

適用対象

AddHostedService<THostedService>(IServiceCollection, Func<IServiceProvider,THostedService>)

ソース:
ServiceCollectionHostedServiceExtensions.cs
ソース:
ServiceCollectionHostedServiceExtensions.cs
ソース:
ServiceCollectionHostedServiceExtensions.cs

指定した型の IHostedService の登録を追加します。

public:
generic <typename THostedService>
 where THostedService : class, Microsoft::Extensions::Hosting::IHostedService[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddHostedService(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Func<IServiceProvider ^, THostedService> ^ implementationFactory);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddHostedService<THostedService> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Func<IServiceProvider,THostedService> implementationFactory) where THostedService : class, Microsoft.Extensions.Hosting.IHostedService;
static member AddHostedService : Microsoft.Extensions.DependencyInjection.IServiceCollection * Func<IServiceProvider, 'HostedService (requires 'HostedService : null and 'HostedService :> Microsoft.Extensions.Hosting.IHostedService)> -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'HostedService : null and 'HostedService :> Microsoft.Extensions.Hosting.IHostedService)
<Extension()>
Public Function AddHostedService(Of THostedService As {Class, IHostedService}) (services As IServiceCollection, implementationFactory As Func(Of IServiceProvider, THostedService)) As IServiceCollection

型パラメーター

THostedService

IHostedService登録する 。

パラメーター

services
IServiceCollection

登録する先の IServiceCollection

implementationFactory
Func<IServiceProvider,THostedService>

サービス実装の新しいインスタンスを作成するファクトリ。

戻り値

元の IServiceCollection

注釈

注意

同じクラスに対してこのメソッドを複数回呼び出さないでください。 これを行うと、指定した最初の HostedService のみが登録されます。 複数の HostedServices を追加するには、 の実装IHostedServiceごとに を明示的に使用AddSingleton<TService>(IServiceCollection, Func<IServiceProvider,TService>)します。

適用対象