ServiceCollectionDescriptorExtensions.TryAddSingleton Método

Definição

Sobrecargas

TryAddSingleton(IServiceCollection, Type)

Adicionará o service especificado como um serviço Singleton à collection se o tipo de serviço ainda não tiver sido registrado.Adds the specified service as a Singleton service to the collection if the service type hasn't already been registered.

TryAddSingleton(IServiceCollection, Type, Func<IServiceProvider,Object>)

Adicionará o service especificado como um serviço de Singleton usando o alocador especificado em implementationFactory à collection se o tipo de serviço ainda não tiver sido registrado.Adds the specified service as a Singleton service using the factory specified in implementationFactory to the collection if the service type hasn't already been registered.

TryAddSingleton(IServiceCollection, Type, Type)

Adicionará o service especificado como um serviço Singleton com a implementação de implementationType à collection se o tipo de serviço ainda não tiver sido registrado.Adds the specified service as a Singleton service with the implementationType implementation to the collection if the service type hasn't already been registered.

TryAddSingleton<TService,TImplementation>(IServiceCollection)

Adicionará o TService especificado como um tipo de implementação de serviço de Singleton especificado em TImplementation à collection se o tipo de serviço ainda não tiver sido registrado.Adds the specified TService as a Singleton service implementation type specified in TImplementation to the collection if the service type hasn't already been registered.

TryAddSingleton<TService>(IServiceCollection)

Adicionará o TService especificado como um serviço Singleton à collection se o tipo de serviço ainda não tiver sido registrado.Adds the specified TService as a Singleton service to the collection if the service type hasn't already been registered.

TryAddSingleton<TService>(IServiceCollection, Func<IServiceProvider,TService>)

Adicionará o TService especificado como um serviço de Singleton usando o alocador especificado em implementationFactory à services se o tipo de serviço ainda não tiver sido registrado.Adds the specified TService as a Singleton service using the factory specified in implementationFactory to the services if the service type hasn't already been registered.

TryAddSingleton<TService>(IServiceCollection, TService)

Adicionará o TService especificado como um serviço de Singleton com uma instância especificada em instance à collection se o tipo de serviço ainda não tiver sido registrado.Adds the specified TService as a Singleton service with an instance specified in instance to the collection if the service type hasn't already been registered.

TryAddSingleton(IServiceCollection, Type)

Adicionará o service especificado como um serviço Singleton à collection se o tipo de serviço ainda não tiver sido registrado.Adds the specified service as a Singleton service to the collection if the service type hasn't already been registered.

public:
[System::Runtime::CompilerServices::Extension]
 static void TryAddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ collection, Type ^ service);
public static void TryAddSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, Type service);
static member TryAddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type -> unit
<Extension()>
Public Sub TryAddSingleton (collection As IServiceCollection, service As Type)

Parâmetros

service
Type

O tipo do serviço a ser registrado.The type of the service to register.

Aplica-se a

TryAddSingleton(IServiceCollection, Type, Func<IServiceProvider,Object>)

Adicionará o service especificado como um serviço de Singleton usando o alocador especificado em implementationFactory à collection se o tipo de serviço ainda não tiver sido registrado.Adds the specified service as a Singleton service using the factory specified in implementationFactory to the collection if the service type hasn't already been registered.

public:
[System::Runtime::CompilerServices::Extension]
 static void TryAddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ collection, Type ^ service, Func<IServiceProvider ^, System::Object ^> ^ implementationFactory);
public static void TryAddSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, Type service, Func<IServiceProvider,object> implementationFactory);
static member TryAddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * Func<IServiceProvider, obj> -> unit
<Extension()>
Public Sub TryAddSingleton (collection As IServiceCollection, service As Type, implementationFactory As Func(Of IServiceProvider, Object))

Parâmetros

service
Type

O tipo do serviço a ser registrado.The type of the service to register.

implementationFactory
Func<IServiceProvider,Object>

O alocador que cria o serviço.The factory that creates the service.

Aplica-se a

TryAddSingleton(IServiceCollection, Type, Type)

Adicionará o service especificado como um serviço Singleton com a implementação de implementationType à collection se o tipo de serviço ainda não tiver sido registrado.Adds the specified service as a Singleton service with the implementationType implementation to the collection if the service type hasn't already been registered.

public:
[System::Runtime::CompilerServices::Extension]
 static void TryAddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ collection, Type ^ service, Type ^ implementationType);
public static void TryAddSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, Type service, Type implementationType);
static member TryAddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * Type -> unit
<Extension()>
Public Sub TryAddSingleton (collection As IServiceCollection, service As Type, implementationType As Type)

Parâmetros

service
Type

O tipo do serviço a ser registrado.The type of the service to register.

implementationType
Type

O tipo de implementação do serviço.The implementation type of the service.

Aplica-se a

TryAddSingleton<TService,TImplementation>(IServiceCollection)

Adicionará o TService especificado como um tipo de implementação de serviço de Singleton especificado em TImplementation à collection se o tipo de serviço ainda não tiver sido registrado.Adds the specified TService as a Singleton service implementation type specified in TImplementation to the collection if the service type hasn't already been registered.

public:
generic <typename TService, typename TImplementation>
 where TService : class where TImplementation : class, TService[System::Runtime::CompilerServices::Extension]
 static void TryAddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ collection);
public static void TryAddSingleton<TService,TImplementation> (this Microsoft.Extensions.DependencyInjection.IServiceCollection collection) where TService : class where TImplementation : class, TService;
static member TryAddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection -> unit (requires 'Service : null)
<Extension()>
Public Sub TryAddSingleton(Of TService As Class, TImplementation As Class) (collection As IServiceCollection)

Parâmetros de tipo

TService

O tipo do serviço a adicionar.The type of the service to add.

TImplementation

O tipo de implementação a ser usado.The type of the implementation to use.

Parâmetros

Aplica-se a

TryAddSingleton<TService>(IServiceCollection)

Adicionará o TService especificado como um serviço Singleton à collection se o tipo de serviço ainda não tiver sido registrado.Adds the specified TService as a Singleton service to the collection if the service type hasn't already been registered.

public:
generic <typename TService>
 where TService : class[System::Runtime::CompilerServices::Extension]
 static void TryAddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ collection);
public static void TryAddSingleton<TService> (this Microsoft.Extensions.DependencyInjection.IServiceCollection collection) where TService : class;
static member TryAddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection -> unit (requires 'Service : null)
<Extension()>
Public Sub TryAddSingleton(Of TService As Class) (collection As IServiceCollection)

Parâmetros de tipo

TService

O tipo do serviço a adicionar.The type of the service to add.

Parâmetros

Aplica-se a

TryAddSingleton<TService>(IServiceCollection, Func<IServiceProvider,TService>)

Adicionará o TService especificado como um serviço de Singleton usando o alocador especificado em implementationFactory à services se o tipo de serviço ainda não tiver sido registrado.Adds the specified TService as a Singleton service using the factory specified in implementationFactory to the services if the service type hasn't already been registered.

public:
generic <typename TService>
 where TService : class[System::Runtime::CompilerServices::Extension]
 static void TryAddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Func<IServiceProvider ^, TService> ^ implementationFactory);
public static void TryAddSingleton<TService> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Func<IServiceProvider,TService> implementationFactory) where TService : class;
static member TryAddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Func<IServiceProvider, 'Service (requires 'Service : null)> -> unit (requires 'Service : null)
<Extension()>
Public Sub TryAddSingleton(Of TService As Class) (services As IServiceCollection, implementationFactory As Func(Of IServiceProvider, TService))

Parâmetros de tipo

TService

O tipo do serviço a adicionar.The type of the service to add.

Parâmetros

implementationFactory
Func<IServiceProvider,TService>

O alocador que cria o serviço.The factory that creates the service.

Aplica-se a

TryAddSingleton<TService>(IServiceCollection, TService)

Adicionará o TService especificado como um serviço de Singleton com uma instância especificada em instance à collection se o tipo de serviço ainda não tiver sido registrado.Adds the specified TService as a Singleton service with an instance specified in instance to the collection if the service type hasn't already been registered.

public:
generic <typename TService>
 where TService : class[System::Runtime::CompilerServices::Extension]
 static void TryAddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ collection, TService instance);
public static void TryAddSingleton<TService> (this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, TService instance) where TService : class;
static member TryAddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * 'Service -> unit (requires 'Service : null)
<Extension()>
Public Sub TryAddSingleton(Of TService As Class) (collection As IServiceCollection, instance As TService)

Parâmetros de tipo

TService

O tipo do serviço a adicionar.The type of the service to add.

Parâmetros

instance
TService

A instância do serviço a ser adicionada.The instance of the service to add.

Aplica-se a