Method TryAddSingleton
TryAddSingleton<TService>(IServiceCollection)
Adds a transient service of the type specified in TService to the specified
IServiceCollection.
Declaration
public static void TryAddSingleton<TService>(this IServiceCollection serviceCollection) where TService : class
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | serviceCollection | The IServiceCollection to add the service to. |
Type Parameters
| Name | Description |
|---|---|
| TService | The type of the service to add. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
TryAddSingleton<TService, TImplementation>(IServiceCollection)
Adds a transient service of the type specified in TService with an
implementation type specified in TImplementation to the specified
IServiceCollection.
Declaration
public static void TryAddSingleton<TService, TImplementation>(this IServiceCollection serviceCollection) where TService : class where TImplementation : class, TService
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | serviceCollection | The IServiceCollection to add the service to. |
Type Parameters
| Name | Description |
|---|---|
| TService | The type of the service to add. |
| TImplementation | The type of the implementation to use. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |