Class NextOrmDbContextExtensions
- Namespace
- NextORM.EntityFrameworkCore
- Assembly
- nextorm.entityframeworkcore.dll
Registers the EF Core-to-nextorm bridge on DbContextOptionsBuilder and resolves a nextorm IDataContext from a DbContext or the DI container.
public static class NextOrmDbContextExtensions
- Inheritance
-
NextOrmDbContextExtensions
- Inherited Members
Remarks
The bridge never owns the EF connection or transaction: it borrows both and leaves EF in control, so disposing an IDataContext resolved through these methods does not close or dispose the DbContext.
Methods
AddNextOrmFromDbContext<TDbContext>(IServiceCollection, Action<DataContextBuilder>?)
Registers a scoped IDataContext that is built from the scope's
TDbContext via GetNextOrmContext(DbContext).
public static IServiceCollection AddNextOrmFromDbContext<TDbContext>(this IServiceCollection services, Action<DataContextBuilder>? configure = null) where TDbContext : DbContext
Parameters
servicesIServiceCollectionThe service collection to register into.
configureAction<DataContextBuilder>Optional nextorm configuration applied after any delegate stored by UseNextOrm(DbContextOptionsBuilder, Action<DataContextBuilder>?).
Returns
- IServiceCollection
The same
servicesfor chaining.
Type Parameters
TDbContextThe EF Core context type already registered in the container.
Exceptions
- ArgumentNullException
servicesis null.
GetNextOrmContext(DbContext)
Creates a nextorm IDataContext over dbContext's
connection, current transaction and model, applying the configuration stored by
UseNextOrm(DbContextOptionsBuilder, Action<DataContextBuilder>?) when the context's options carry it.
public static IDataContext GetNextOrmContext(this DbContext dbContext)
Parameters
dbContextDbContextThe EF Core context whose connection, model and current transaction are reused.
Returns
- IDataContext
An IDataContext that executes on the EF connection and inside EF's current transaction when one is active.
Exceptions
- ArgumentNullException
dbContextis null.- InvalidOperationException
The EF provider reported by
ProviderNameis not one of the supported providers.
UseNextOrm(DbContextOptionsBuilder, Action<DataContextBuilder>?)
Stores the optional nextorm configuration on optionsBuilder, so that
GetNextOrmContext(DbContext) can build a context without taking the delegate again.
public static DbContextOptionsBuilder UseNextOrm(this DbContextOptionsBuilder optionsBuilder, Action<DataContextBuilder>? configure = null)
Parameters
optionsBuilderDbContextOptionsBuilderThe EF Core options builder to extend.
configureAction<DataContextBuilder>Optional nextorm configuration applied after the provider is selected.
Returns
- DbContextOptionsBuilder
The same
optionsBuilderfor chaining.
Exceptions
- ArgumentNullException
optionsBuilderis null.
UseNextOrm<TContext>(DbContextOptionsBuilder<TContext>, Action<DataContextBuilder>?)
Stores the optional nextorm configuration on the strongly typed optionsBuilder,
so that GetNextOrmContext(DbContext) can build a context without taking the delegate again.
public static DbContextOptionsBuilder<TContext> UseNextOrm<TContext>(this DbContextOptionsBuilder<TContext> optionsBuilder, Action<DataContextBuilder>? configure = null) where TContext : DbContext
Parameters
optionsBuilderDbContextOptionsBuilder<TContext>The EF Core options builder to extend.
configureAction<DataContextBuilder>Optional nextorm configuration applied after the provider is selected.
Returns
- DbContextOptionsBuilder<TContext>
The same
optionsBuilderfor chaining.
Type Parameters
TContextThe EF Core context type the options belong to.
Exceptions
- ArgumentNullException
optionsBuilderis null.