ServiceCollectionDbServiceExtensions Class
Namespace: PTS
Assembly: PTS.DomainFramework.Infrastructure.dll
Service scoping extension methods for Microsoft.Extensions.DependencyInjection.IServiceCollection
Syntax
public static class ServiceCollectionDbServiceExtensions
Inheritance
Methods
AddInfrastructure<TContext>(IServiceCollection, DbContextOptions<TContext>, ServiceLifetime)
Registers the given context and all its inherited base types and implemented interfaces as services.
Declaration
public static IServiceCollection AddInfrastructure<TContext>(this IServiceCollection serviceCollection, DbContextOptions<TContext> options, ServiceLifetime lifeTime = ServiceLifetime.Scoped)
where TContext : DbContext, IEntityServiceProvider
Parameters
Type | Name | Description |
---|---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection | serviceCollection | The collection to add services to.. |
Microsoft.EntityFrameworkCore.DbContextOptions<TContext> | options | The options for the |
Microsoft.Extensions.DependencyInjection.ServiceLifetime | lifeTime | Lifetime of the context service. |
Returns
Type | Description |
---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection | The same service collection so that multiple calls can be chained. |
Type Parameters
Name | Description |
---|---|
TContext | The type of the context. |
Remarks
Using this method is higly recommended in applications with multiple DbContext generations to ensure dependency injection service compatibility accross assemlies.
AddInfrastructure<TContext>(IServiceCollection, Action<DbContextOptionsBuilder<TContext>>, ServiceLifetime)
Registers the given context and all its inherited base types and implemented interfaces as services.
Declaration
public static IServiceCollection AddInfrastructure<TContext>(this IServiceCollection serviceCollection, Action<DbContextOptionsBuilder<TContext>> optionsAction, ServiceLifetime lifeTime = ServiceLifetime.Scoped)
where TContext : DbContext, IEntityServiceProvider
Parameters
Type | Name | Description |
---|---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection | serviceCollection | The collection to add services to. |
System.Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext>> | optionsAction | Action method performing the context options configuration. |
Microsoft.Extensions.DependencyInjection.ServiceLifetime | lifeTime | Lifetime of the context service. |
Returns
Type | Description |
---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection | The same service collection so that multiple calls can be chained. |
Type Parameters
Name | Description |
---|---|
TContext | The type of the context. |
Remarks
Using this method is higly recommended in applications with multiple DbContext generations to ensure dependency injection service compatibility accross assemlies.
AddInfrastructure<TContext>(IServiceCollection, Action<IServiceProvider, DbContextOptionsBuilder<TContext>>, ServiceLifetime)
Registers the given context and all its inherited base types and implemented interfaces as services.
Declaration
public static IServiceCollection AddInfrastructure<TContext>(this IServiceCollection serviceCollection, Action<IServiceProvider, DbContextOptionsBuilder<TContext>> optionsAction, ServiceLifetime lifeTime = ServiceLifetime.Scoped)
where TContext : DbContext, IEntityServiceProvider
Parameters
Type | Name | Description |
---|---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection | serviceCollection | The collection to add services to. |
System.Action<System.IServiceProvider, Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext>> | optionsAction | Action method performing the context options configuration. |
Microsoft.Extensions.DependencyInjection.ServiceLifetime | lifeTime | Lifetime of the context service. |
Returns
Type | Description |
---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection | The same service collection so that multiple calls can be chained. |
Type Parameters
Name | Description |
---|---|
TContext | The type of the context. |
Remarks
Using this method is higly recommended in applications with multiple DbContext generations to ensure dependency injection service compatibility accross assemlies.
AddRepositories<TContext>(IServiceCollection)
Declaration
public static IServiceCollection AddRepositories<TContext>(this IServiceCollection serviceCollection)
where TContext : DbContext, IEntityServiceProvider
Parameters
Type | Name | Description |
---|---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection | serviceCollection |
Returns
Type | Description |
---|---|
Microsoft.Extensions.DependencyInjection.IServiceCollection |
Type Parameters
Name | Description |
---|---|
TContext |