ServiceCollectionMap.TryAddSingleton Method

Definition

Overloads

TryAddSingleton(Type, Type)

Adds a Singleton service implemented by the given concrete type if no service for the given service type has already been registered.

TryAddSingleton(Type, Func<IServiceProvider,Object>)

Adds a Singleton service implemented by the given factory if no service for the given service type has already been registered.

TryAddSingleton(Type, Object)

Adds a Singleton service implemented by the given instance if no service for the given service type has already been registered.

TryAddSingleton<TService,TImplementation>()

Adds a Singleton service implemented by the given concrete type if no service for the given service type has already been registered.

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

Adds a Singleton service implemented by the given factory if no service for the given service type has already been registered.

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

Adds a Singleton service implemented by the given factory if no service for the given service type has already been registered.

TryAddSingleton<TService>(TService)

Adds a Singleton service implemented by the given instance if no service for the given service type has already been registered.

TryAddSingleton(Type, Type)

Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs

Adds a Singleton service implemented by the given concrete type if no service for the given service type has already been registered.

C#
public virtual Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap TryAddSingleton (Type serviceType, Type implementationType);

Parameters

serviceType
Type

The contract for the service.

implementationType
Type

The concrete type that implements the service.

Returns

The map, such that further calls can be chained.

Applies to

Entity Framework Core 9.0 and other versions
Product Versions
Entity Framework Core 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0

TryAddSingleton(Type, Func<IServiceProvider,Object>)

Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs

Adds a Singleton service implemented by the given factory if no service for the given service type has already been registered.

C#
public virtual Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap TryAddSingleton (Type serviceType, Func<IServiceProvider,object> factory);

Parameters

serviceType
Type

The contract for the service.

factory
Func<IServiceProvider,Object>

The factory that implements the service.

Returns

The map, such that further calls can be chained.

Applies to

Entity Framework Core 9.0 and other versions
Product Versions
Entity Framework Core 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0

TryAddSingleton(Type, Object)

Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs

Adds a Singleton service implemented by the given instance if no service for the given service type has already been registered.

C#
public virtual Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap TryAddSingleton (Type serviceType, object implementation);

Parameters

serviceType
Type

The contract for the service.

implementation
Object

The object that implements the service.

Returns

The map, such that further calls can be chained.

Applies to

Entity Framework Core 9.0 and other versions
Product Versions
Entity Framework Core 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0

TryAddSingleton<TService,TImplementation>()

Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs

Adds a Singleton service implemented by the given concrete type if no service for the given service type has already been registered.

C#
public virtual Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap TryAddSingleton<TService,TImplementation> () where TService : class where TImplementation : class, TService;

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that implements the service.

Returns

The map, such that further calls can be chained.

Applies to

Entity Framework Core 9.0 and other versions
Product Versions
Entity Framework Core 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0

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

Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs

Adds a Singleton service implemented by the given factory if no service for the given service type has already been registered.

C#
public virtual Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap TryAddSingleton<TService,TImplementation> (Func<IServiceProvider,TImplementation> factory) where TService : class where TImplementation : class, TService;

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that the given factory creates.

Parameters

factory
Func<IServiceProvider,TImplementation>

The factory that implements the service.

Returns

The map, such that further calls can be chained.

Applies to

Entity Framework Core 9.0 and other versions
Product Versions
Entity Framework Core 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0

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

Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs

Adds a Singleton service implemented by the given factory if no service for the given service type has already been registered.

C#
public virtual Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap TryAddSingleton<TService> (Func<IServiceProvider,TService> factory) where TService : class;

Type Parameters

TService

The contract for the service.

Parameters

factory
Func<IServiceProvider,TService>

The factory that implements the service.

Returns

The map, such that further calls can be chained.

Applies to

Entity Framework Core 9.0 and other versions
Product Versions
Entity Framework Core 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0

TryAddSingleton<TService>(TService)

Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs
Source:
ServiceCollectionMap.cs

Adds a Singleton service implemented by the given instance if no service for the given service type has already been registered.

C#
public virtual Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap TryAddSingleton<TService> (TService implementation) where TService : class;

Type Parameters

TService

The contract for the service.

Parameters

implementation
TService

The object that implements the service.

Returns

The map, such that further calls can be chained.

Applies to

Entity Framework Core 9.0 and other versions
Product Versions
Entity Framework Core 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0