ServiceCollectionDiExtensions Class
Namespace: PTS
Assembly: PTS.DependencyInjection.dll
Various helper methods for Microsoft.Extensions.DependencyInjection.IServiceCollection
Syntax
public static class ServiceCollectionDiExtensions
Inheritance
Methods
Add<TService, TImplementation>(IServiceCollection, ServiceLifetime)
Declaration
public static IServiceCollection Add<TService, TImplementation>(this IServiceCollection serviceCollection, ServiceLifetime lifeTime)
where TService : class where TImplementation : class, TService
Parameters
Type | Name | Description |
---|---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection | serviceCollection | |
Microsoft.Extensions.DependencyInjection.ServiceLifetime | lifeTime |
Returns
Type | Description |
---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection |
Type Parameters
Name | Description |
---|---|
TService | |
TImplementation |
AddBaseTypesAsProxyServices<TService>(IServiceCollection, Type, Boolean, ServiceLifetime)
Adds the base types of a service as proxy services that point to the same service instance.
Declaration
public static IServiceCollection AddBaseTypesAsProxyServices<TService>(this IServiceCollection serviceCollection, Type baseType = null, bool excludeBaseTypeAssembly = false, ServiceLifetime lifeTime = ServiceLifetime.Scoped)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection | serviceCollection | The service collection to add the proxy services to. |
System.Type | baseType | The base type where the inheritance traversal will stop. |
System.Boolean | excludeBaseTypeAssembly | if set to |
Microsoft.Extensions.DependencyInjection.ServiceLifetime | lifeTime |
Returns
Type | Description |
---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection |
Type Parameters
Name | Description |
---|---|
TService | The type of the service to point base types to. |
AddDefaultServices(IServiceCollection, Type[])
Attempts to add services that implement ISeedWork and itnerface types in [withInterfaces] to service collection found in assemblies via reflection.
Services already added to IServiceCollection
will not be overriden.
Declaration
public static IServiceCollection AddDefaultServices(this IServiceCollection services, params Type[] withInterfaces)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection | services | The |
System.Type[] | withInterfaces | The |
Returns
Type | Description |
---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection | A reference to the current instance of |
AddParentProviderReference(IServiceCollection, IServiceProvider)
Adds deafult implementation of the IParentServiceProvider service with assigned provider.
Declaration
public static IServiceCollection AddParentProviderReference(this IServiceCollection serviceCollection, IServiceProvider provider)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection | serviceCollection | The service collection to add the service to. |
System.IServiceProvider | provider | A reference to this instance after the operation has completed for chaining. |
Returns
Type | Description |
---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection |
TryAdd<TService, TImplementation>(IServiceCollection, ServiceLifetime)
Declaration
public static IServiceCollection TryAdd<TService, TImplementation>(this IServiceCollection serviceCollection, ServiceLifetime lifeTime)
where TService : class where TImplementation : class, TService
Parameters
Type | Name | Description |
---|---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection | serviceCollection | |
Microsoft.Extensions.DependencyInjection.ServiceLifetime | lifeTime |
Returns
Type | Description |
---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection |
Type Parameters
Name | Description |
---|---|
TService | |
TImplementation |