TryAdd Method
Definition
- Namespace
- Cuemon.Extensions.DependencyInjection
- Assemblies
- Cuemon.Extensions.DependencyInjection.dll
TryAdd<TService>(IServiceCollection, Action<TypeForwardServiceOptions>)
Adds the specified TService with the configured setup to the services if the service type has not already been registered.
public static IServiceCollection TryAdd<TService>(this IServiceCollection services, Action<TypeForwardServiceOptions> setup = null) where TService : class
Parameters
servicesIServiceCollectionThe IServiceCollection to add the service to.
setupAction<TypeForwardServiceOptions>The TypeForwardServiceOptions which may be configured.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
Type Parameters
TServiceThe type of the service to add.
Remarks
If the underlying type of TService implements IDependencyInjectionMarker<TMarker> interface then this is automatically handled.
TryAdd<TService, TImplementation>(IServiceCollection, Action<TypeForwardServiceOptions>)
Adds the specified TService with the TImplementation and configured setup to the services if the service type has not already been registered.
public static IServiceCollection TryAdd<TService, TImplementation>(this IServiceCollection services, Action<TypeForwardServiceOptions> setup = null) where TService : class where TImplementation : class, TService
Parameters
servicesIServiceCollectionThe IServiceCollection to add the service to.
setupAction<TypeForwardServiceOptions>The TypeForwardServiceOptions which may be configured.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
Type Parameters
TServiceThe type of the service to add.
TImplementationThe type of the implementation to use.
TryAdd(IServiceCollection, Type, Type, Action<TypeForwardServiceOptions>)
Adds the specified service with the implementation and configured setup to the services if the service type has not already been registered.
public static IServiceCollection TryAdd(this IServiceCollection services, Type service, Type implementation, Action<TypeForwardServiceOptions> setup = null)
Parameters
servicesIServiceCollectionThe IServiceCollection to add the service to.
serviceTypeThe type of the service to register.
implementationTypeThe implementation type of the service.
setupAction<TypeForwardServiceOptions>The TypeForwardServiceOptions which may be configured.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
TryAdd<TService>(IServiceCollection, Func<IServiceProvider, TService>, Action<TypeForwardServiceOptions>)
Adds the specified TService with the configured setup to the services if the service type has not already been registered.
public static IServiceCollection TryAdd<TService>(this IServiceCollection services, Func<IServiceProvider, TService> implementationFactory, Action<TypeForwardServiceOptions> setup = null) where TService : class
Parameters
servicesIServiceCollectionThe IServiceCollection to add the service to.
implementationFactoryFunc<IServiceProvider, TService>The function delegate that creates the service.
setupAction<TypeForwardServiceOptions>The TypeForwardServiceOptions which may be configured.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
Type Parameters
TServiceThe type of the service to add.
TryAdd<TService, TImplementation>(IServiceCollection, Func<IServiceProvider, TImplementation>, Action<TypeForwardServiceOptions>)
Adds the specified TService with the TImplementation and configured setup to the services if the service type has not already been registered.
public static IServiceCollection TryAdd<TService, TImplementation>(this IServiceCollection services, Func<IServiceProvider, TImplementation> implementationFactory, Action<TypeForwardServiceOptions> setup = null) where TService : class where TImplementation : class, TService
Parameters
servicesIServiceCollectionThe IServiceCollection to add the service to.
implementationFactoryFunc<IServiceProvider, TImplementation>The function delegate that creates the service.
setupAction<TypeForwardServiceOptions>The TypeForwardServiceOptions which may be configured.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
Type Parameters
TServiceThe type of the service to add.
TImplementationThe type of the implementation to use.
TryAdd(IServiceCollection, Type, Func<IServiceProvider, object>, Action<TypeForwardServiceOptions>)
Adds the specified service with the implementationFactory and configured setup to the services if the service type has not already been registered.
public static IServiceCollection TryAdd(this IServiceCollection services, Type service, Func<IServiceProvider, object> implementationFactory, Action<TypeForwardServiceOptions> setup = null)
Parameters
servicesIServiceCollectionThe IServiceCollection to add the service to.
serviceTypeThe type of the service to register.
implementationFactoryFunc<IServiceProvider, object>The function delegate that creates the service.
setupAction<TypeForwardServiceOptions>The TypeForwardServiceOptions which may be configured.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
TryAdd<TService, TImplementation>(IServiceCollection, ServiceLifetime)
Adds the specified TService with the TImplementation and lifetime to the services if the service type has not already been registered.
public static IServiceCollection TryAdd<TService, TImplementation>(this IServiceCollection services, ServiceLifetime lifetime) where TService : class where TImplementation : class, TService
Parameters
servicesIServiceCollectionThe IServiceCollection to add the service to.
lifetimeServiceLifetimeThe lifetime of the service.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
Type Parameters
TServiceThe type of the service to add.
TImplementationThe type of the implementation to use.
TryAdd<TService, TImplementation, TOptions>(IServiceCollection, ServiceLifetime, Action<TOptions>)
Adds the specified TService with the TImplementation and lifetime to the services if the service type has not already been registered.
public static IServiceCollection TryAdd<TService, TImplementation, TOptions>(this IServiceCollection services, ServiceLifetime lifetime, Action<TOptions> setup) where TService : class where TImplementation : class, TService where TOptions : class, new()
Parameters
servicesIServiceCollectionThe IServiceCollection to add the service to.
lifetimeServiceLifetimeThe lifetime of the service.
setupAction<TOptions>The
TOptionswhich need to be configured.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
Type Parameters
TServiceThe type of the service to add.
TImplementationThe type of the implementation to use.
TOptionsThe type of the configured options.
TryAdd(IServiceCollection, Type, Type, ServiceLifetime)
Adds the specified service with the implementation and lifetime to the services if the service type has not already been registered.
public static IServiceCollection TryAdd(this IServiceCollection services, Type service, Type implementation, ServiceLifetime lifetime)
Parameters
servicesIServiceCollectionThe IServiceCollection to add the service to.
serviceTypeThe type of the service to register.
implementationTypeThe implementation type of the service.
lifetimeServiceLifetimeThe lifetime of the service.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
TryAdd<TOptions>(IServiceCollection, Type, Type, ServiceLifetime, Action<TOptions>)
Adds the specified service with the implementation and lifetime to the services if the service type has not already been registered.
public static IServiceCollection TryAdd<TOptions>(this IServiceCollection services, Type service, Type implementation, ServiceLifetime lifetime, Action<TOptions> setup) where TOptions : class, new()
Parameters
servicesIServiceCollectionThe IServiceCollection to add the service to.
serviceTypeThe type of the service to register.
implementationTypeThe implementation type of the service.
lifetimeServiceLifetimeThe lifetime of the service.
setupAction<TOptions>The
TOptionswhich need to be configured.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
Type Parameters
TOptionsThe type of the configured options.
TryAdd<TService, TImplementation>(IServiceCollection, Func<IServiceProvider, TImplementation>, ServiceLifetime)
Adds the specified TService with the TImplementation and lifetime to the services if the service type has not already been registered.
public static IServiceCollection TryAdd<TService, TImplementation>(this IServiceCollection services, Func<IServiceProvider, TImplementation> implementationFactory, ServiceLifetime lifetime) where TService : class where TImplementation : class, TService
Parameters
servicesIServiceCollectionThe IServiceCollection to add the service to.
implementationFactoryFunc<IServiceProvider, TImplementation>The function delegate that creates the service.
lifetimeServiceLifetimeThe lifetime of the service.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
Type Parameters
TServiceThe type of the service to add.
TImplementationThe type of the implementation to use.
TryAdd<TService, TImplementation, TOptions>(IServiceCollection, Func<IServiceProvider, TImplementation>, ServiceLifetime, Action<TOptions>)
Adds the specified TService with the TImplementation and lifetime to the services if the service type has not already been registered.
public static IServiceCollection TryAdd<TService, TImplementation, TOptions>(this IServiceCollection services, Func<IServiceProvider, TImplementation> implementationFactory, ServiceLifetime lifetime, Action<TOptions> setup) where TService : class where TImplementation : class, TService where TOptions : class, new()
Parameters
servicesIServiceCollectionThe IServiceCollection to add the service to.
implementationFactoryFunc<IServiceProvider, TImplementation>The function delegate that creates the service.
lifetimeServiceLifetimeThe lifetime of the service.
setupAction<TOptions>The
TOptionswhich need to be configured.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
Type Parameters
TServiceThe type of the service to add.
TImplementationThe type of the implementation to use.
TOptionsThe type of the configured options.
TryAdd(IServiceCollection, Type, Func<IServiceProvider, object>, ServiceLifetime)
Adds the specified service with the implementationFactory and lifetime to the services if the service type has not already been registered.
public static IServiceCollection TryAdd(this IServiceCollection services, Type service, Func<IServiceProvider, object> implementationFactory, ServiceLifetime lifetime)
Parameters
servicesIServiceCollectionThe IServiceCollection to add the service to.
serviceTypeThe type of the service to register.
implementationFactoryFunc<IServiceProvider, object>The function delegate that creates the service.
lifetimeServiceLifetimeThe lifetime of the service.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
TryAdd<TOptions>(IServiceCollection, Type, Func<IServiceProvider, object>, ServiceLifetime, Action<TOptions>)
Adds the specified service with the implementationFactory and lifetime to the services if the service type has not already been registered.
public static IServiceCollection TryAdd<TOptions>(this IServiceCollection services, Type service, Func<IServiceProvider, object> implementationFactory, ServiceLifetime lifetime, Action<TOptions> setup) where TOptions : class, new()
Parameters
servicesIServiceCollectionThe IServiceCollection to add the service to.
serviceTypeThe type of the service to register.
implementationFactoryFunc<IServiceProvider, object>The function delegate that creates the service.
lifetimeServiceLifetimeThe lifetime of the service.
setupAction<TOptions>The
TOptionswhich need to be configured.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
Type Parameters
TOptionsThe type of the configured options.