ServiceCollectionDescriptorExtensions.TryAddSingleton ServiceCollectionDescriptorExtensions.TryAddSingleton ServiceCollectionDescriptorExtensions.TryAddSingleton Method

Definition

Overloads

TryAddSingleton(IServiceCollection, Type) TryAddSingleton(IServiceCollection, Type) TryAddSingleton(IServiceCollection, Type)

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>) TryAddSingleton(IServiceCollection, Type, Func<IServiceProvider,Object>) TryAddSingleton(IServiceCollection, Type, Func<IServiceProvider,Object>)

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) TryAddSingleton(IServiceCollection, Type, Type) TryAddSingleton(IServiceCollection, Type, Type)

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) TryAddSingleton<TService,TImplementation>(IServiceCollection) TryAddSingleton<TService,TImplementation>(IServiceCollection)

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) TryAddSingleton<TService>(IServiceCollection) TryAddSingleton<TService>(IServiceCollection)

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>) TryAddSingleton<TService>(IServiceCollection, Func<IServiceProvider,TService>) TryAddSingleton<TService>(IServiceCollection, Func<IServiceProvider,TService>)

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) TryAddSingleton<TService>(IServiceCollection, TService) TryAddSingleton<TService>(IServiceCollection, TService)

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) TryAddSingleton(IServiceCollection, Type) TryAddSingleton(IServiceCollection, Type)

Adds the specified service as a Singleton service to the collection if the service type hasn't already been registered.

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)

Parameters

service
Type Type Type

The type of the service to register.

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

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 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))

Parameters

service
Type Type Type

The type of the service to register.

implementationFactory
Func<IServiceProvider,Object>

The factory that creates the service.

TryAddSingleton(IServiceCollection, Type, Type) TryAddSingleton(IServiceCollection, Type, Type) TryAddSingleton(IServiceCollection, Type, Type)

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 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)

Parameters

service
Type Type Type

The type of the service to register.

implementationType
Type Type Type

The implementation type of the service.

TryAddSingleton<TService,TImplementation>(IServiceCollection) TryAddSingleton<TService,TImplementation>(IServiceCollection) TryAddSingleton<TService,TImplementation>(IServiceCollection)

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 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)

Type Parameters

TService

The type of the service to add.

TImplementation

The type of the implementation to use.

Parameters

TryAddSingleton<TService>(IServiceCollection) TryAddSingleton<TService>(IServiceCollection) TryAddSingleton<TService>(IServiceCollection)

Adds the specified TService as a Singleton service to the collection if the service type hasn't already been registered.

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)

Type Parameters

TService

The type of the service to add.

Parameters

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

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 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))

Type Parameters

TService

The type of the service to add.

Parameters

implementationFactory
Func<IServiceProvider,TService>

The factory that creates the service.

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

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 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)

Type Parameters

TService

The type of the service to add.

Parameters

instance

The instance of the service to add.

Applies to