ServiceCollectionHostedServiceExtensions.AddHostedService Metode

Definisi

Overload

AddHostedService<THostedService>(IServiceCollection)

IHostedService Tambahkan pendaftaran untuk jenis yang diberikan.

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

IHostedService Tambahkan pendaftaran untuk jenis yang diberikan.

AddHostedService<THostedService>(IServiceCollection)

Sumber:
ServiceCollectionHostedServiceExtensions.cs
Sumber:
ServiceCollectionHostedServiceExtensions.cs
Sumber:
ServiceCollectionHostedServiceExtensions.cs
Sumber:
ServiceCollectionHostedServiceExtensions.cs

IHostedService Tambahkan pendaftaran untuk jenis yang diberikan.

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

Jenis parameter

THostedService

Untuk IHostedService mendaftar.

Parameter

services
IServiceCollection

untuk IServiceCollection mendaftar dengan.

Mengembalikan

Yang asli IServiceCollection.

Keterangan

Catatan

Anda tidak boleh memanggil metode ini beberapa kali untuk kelas yang sama. Melakukannya hanya akan mendaftarkan HostedService pertama yang Anda sediakan. Untuk menambahkan beberapa HostedServices, gunakan AddSingleton<TService>(IServiceCollection) untuk setiap implementasi IHostedService secara eksplisit.

Berlaku untuk

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

Sumber:
ServiceCollectionHostedServiceExtensions.cs
Sumber:
ServiceCollectionHostedServiceExtensions.cs
Sumber:
ServiceCollectionHostedServiceExtensions.cs
Sumber:
ServiceCollectionHostedServiceExtensions.cs

IHostedService Tambahkan pendaftaran untuk jenis yang diberikan.

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

Jenis parameter

THostedService

Untuk IHostedService mendaftar.

Parameter

services
IServiceCollection

untuk IServiceCollection mendaftar dengan.

implementationFactory
Func<IServiceProvider,THostedService>

Pabrik untuk membuat instans baru implementasi layanan.

Mengembalikan

Yang asli IServiceCollection.

Keterangan

Catatan

Anda tidak boleh memanggil metode ini beberapa kali untuk kelas yang sama. Melakukannya hanya akan mendaftarkan HostedService pertama yang Anda sediakan. Untuk menambahkan beberapa HostedServices, gunakan AddSingleton<TService>(IServiceCollection, Func<IServiceProvider,TService>) untuk setiap implementasi IHostedService secara eksplisit.

Berlaku untuk