Architect.EntityFramework.DbContextManagement (nuget): Manage your DbContexts the right way.  The persistence or infrastructure layer uses the DbContext (e.g. from a repository). Controlling its scope and transaction lifetime, however, is ideally the reponsibility of the orchestrating layer (e.g. from an application service). This package adds that ability to Entity Framework Core 5.0.0 and up.  https://github.com/TheArchitectDev/Architect.EntityFramework.DbContextManagement  Release notes:  2.0.0: - BREAKING: Now using AmbientContexts 2.0.0. - Semi-breaking: Failure on commit (extremely rare) now throws IOException instead of Exception. - Added static DbContextScope<TDbContext>.HasDbContext, to match the feature set of IDbContextAccessor. - Retries now ensure that the connection is closed before retrying, to avoid the risk of leaking session state. (As with EF's DbContext disposal in general, this relies on the database provider's connection reset.) - Scoped execution now protects against dangerous "failure on commit" retries even on manual commits (rather than just on IExecutionScope's implicit commit). - Worked around an EF bug where the DbContext would obscure the exception caused by a broken model behind an ObjectDisposedException, even though DbContext._disposed=false. - Scoped execution: Fixed a bug where the exception caused by a broken model would be obscured behind a wrongful IncompatibleVersionException. - MockDbContextProvider: Fixed a bug where nested scopes would not work as expected. - MockDbContextProvider: Fixed a bug where soft attempts to roll back a transaction when there was none could cause an unintended TransactionAbortedException.  1.0.1: - Now using AmbientContexts 1.1.1, which fixes extremely rare bugs and improves performance.
Keywords: DbContext|DbContextScope|AmbientDbContext|EntityFramework|Entity|Framework|EF|Core|EfCore|AmbientContext|AmbientScope|ambient|context|scope|IoC|inversion|control|transaction|UnitOfWork|unit|work