-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from marcwittke/develop
6.1.1
- Loading branch information
Showing
19 changed files
with
58 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 5 additions & 25 deletions
30
src/implementations/Backend.Fx.EfCorePersistence/DbContextTransactionDecorator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,32 @@ | ||
using System; | ||
using System.Data.Common; | ||
using System.Security.Principal; | ||
using Backend.Fx.Patterns.DependencyInjection; | ||
using Backend.Fx.Patterns.Transactions; | ||
using Backend.Fx.Patterns.UnitOfWork; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Backend.Fx.EfCorePersistence | ||
{ | ||
/// <summary> | ||
/// Makes sure the DbContext gets enlisted in a transaction. The transaction gets started, before IUnitOfWork.Begin() is being called | ||
/// and gets committed after IUnitOfWork.Complete() is being called | ||
/// Makes sure the DbContext gets enlisted in a transaction. | ||
/// </summary> | ||
public class DbContextTransactionDecorator : IUnitOfWork | ||
public class DbContextTransactionDecorator : DbTransactionDecorator | ||
{ | ||
public DbContextTransactionDecorator(ITransactionContext transactionContext, DbContext dbContext, IUnitOfWork unitOfWork) | ||
: base(transactionContext, unitOfWork) | ||
{ | ||
TransactionContext = transactionContext; | ||
DbContext = dbContext; | ||
UnitOfWork = unitOfWork; | ||
} | ||
|
||
public IUnitOfWork UnitOfWork { get; } | ||
|
||
public ITransactionContext TransactionContext { get; } | ||
|
||
public DbContext DbContext { get; } | ||
|
||
public ICurrentTHolder<IIdentity> IdentityHolder => UnitOfWork.IdentityHolder; | ||
|
||
public void Begin() | ||
public override void Begin() | ||
{ | ||
TransactionContext.BeginTransaction(); | ||
base.Begin(); | ||
if (DbContext.Database.GetDbConnection() != TransactionContext.CurrentTransaction.Connection) | ||
{ | ||
throw new InvalidOperationException("The connection used by the DbContext instance does not equal the connection of the transaction context"); | ||
} | ||
DbContext.Database.UseTransaction((DbTransaction) TransactionContext.CurrentTransaction); | ||
UnitOfWork.Begin(); | ||
} | ||
|
||
public void Complete() | ||
{ | ||
UnitOfWork.Complete(); | ||
TransactionContext.CommitTransaction(); | ||
} | ||
|
||
public void Dispose() | ||
{ } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
tests/Backend.Fx.EfCorePersistence.Tests/Migrations/20190624150947_Initial.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.