ServiceCollectionHostedServiceExtensions.AddHostedService Methode

Definitie

Overloads

Name Description
AddHostedService<THostedService>(IServiceCollection)

Voeg een IHostedService registratie toe voor het opgegeven type.

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

Voeg een IHostedService registratie toe voor het opgegeven type.

AddHostedService<THostedService>(IServiceCollection)

Bron:
ServiceCollectionHostedServiceExtensions.cs
Bron:
ServiceCollectionHostedServiceExtensions.cs
Bron:
ServiceCollectionHostedServiceExtensions.cs
Bron:
ServiceCollectionHostedServiceExtensions.cs

Voeg een IHostedService registratie toe voor het opgegeven type.

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

Type parameters

THostedService

Een IHostedService te registreren.

Parameters

services
IServiceCollection

De IServiceCollection te registreren bij.

Retouren

Het origineel IServiceCollection.

Voorbeelden

De volgende code laat zien hoe u een gehoste service registreert terwijl u ook het werkelijke THostedService type registreert.

services.AddSingleton<SomeService>();
services.AddHostedService(sp => sp.GetRequiredService<SomeService>());

Opmerkingen

Houd er rekening mee dat hiermee specifiek registratie wordt IHostedService gemaakt. Niet voor het werkelijke THostedService type. Als u het werkelijke type wilt registreren, moet u dit afzonderlijk doen.

Van toepassing op

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

Bron:
ServiceCollectionHostedServiceExtensions.cs
Bron:
ServiceCollectionHostedServiceExtensions.cs
Bron:
ServiceCollectionHostedServiceExtensions.cs
Bron:
ServiceCollectionHostedServiceExtensions.cs

Voeg een IHostedService registratie toe voor het opgegeven type.

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

Type parameters

THostedService

Een IHostedService te registreren.

Parameters

services
IServiceCollection

De IServiceCollection te registreren bij.

implementationFactory
Func<IServiceProvider,THostedService>

Een fabriek voor het maken van nieuwe exemplaren van de service-implementatie.

Retouren

Het origineel IServiceCollection.

Voorbeelden

De volgende code laat zien hoe u een gehoste service registreert terwijl u ook het werkelijke THostedService type registreert.

services.AddSingleton<SomeService>(implementationFactory);
services.AddHostedService(sp => sp.GetRequiredService<SomeService>());

Opmerkingen

Houd er rekening mee dat hiermee specifiek registratie wordt IHostedService gemaakt. Niet voor het werkelijke THostedService type. Als u het werkelijke type wilt registreren, moet u dit afzonderlijk doen.

Van toepassing op