ServiceCollectionHostedServiceExtensions.AddHostedService Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Aşırı Yüklemeler
| Name | Description |
|---|---|
| AddHostedService<THostedService>(IServiceCollection) |
Verilen tür için bir IHostedService kayıt ekleyin. |
| AddHostedService<THostedService>(IServiceCollection, Func<IServiceProvider,THostedService>) |
Verilen tür için bir IHostedService kayıt ekleyin. |
AddHostedService<THostedService>(IServiceCollection)
Verilen tür için bir IHostedService kayıt ekleyin.
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
Tür Parametreleri
- THostedService
Kayıt için bir IHostedService .
Parametreler
- services
- IServiceCollection
IServiceCollection Ile kaydedilecek.
Döndürülenler
Özgün IServiceCollection.
Örnekler
Aşağıdaki kod, gerçek THostedService türü kaydederken barındırılan bir hizmetin nasıl kaydedileceklerini gösterir.
services.AddSingleton<SomeService>();
services.AddHostedService(sp => sp.GetRequiredService<SomeService>());
Açıklamalar
Bunun özellikle için IHostedService kayıt oluşturduğunu unutmayın. Gerçek THostedService tür için değil. Gerçek türü kaydetmek istiyorsanız, bunu ayrı olarak yapmanız gerekir.
Şunlara uygulanır
AddHostedService<THostedService>(IServiceCollection, Func<IServiceProvider,THostedService>)
Verilen tür için bir IHostedService kayıt ekleyin.
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
Tür Parametreleri
- THostedService
Kayıt için bir IHostedService .
Parametreler
- services
- IServiceCollection
IServiceCollection Ile kaydedilecek.
- implementationFactory
- Func<IServiceProvider,THostedService>
Hizmet uygulamasının yeni örneklerini oluşturmak için bir fabrika.
Döndürülenler
Özgün IServiceCollection.
Örnekler
Aşağıdaki kod, gerçek THostedService türü kaydederken barındırılan bir hizmetin nasıl kaydedileceklerini gösterir.
services.AddSingleton<SomeService>(implementationFactory);
services.AddHostedService(sp => sp.GetRequiredService<SomeService>());
Açıklamalar
Bunun özellikle için IHostedService kayıt oluşturduğunu unutmayın. Gerçek THostedService tür için değil. Gerçek türü kaydetmek istiyorsanız, bunu ayrı olarak yapmanız gerekir.