-
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.
UoW: Decorators for Connection and Transaction
- Loading branch information
1 parent
1741fa0
commit b563b4b
Showing
23 changed files
with
429 additions
and
467 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
26 changes: 26 additions & 0 deletions
26
src/abstractions/Backend.Fx/Patterns/Transactions/ReadonlyDecorator.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Data; | ||
|
||
namespace Backend.Fx.Patterns.Transactions | ||
{ | ||
public class ReadonlyDecorator : ITransactionContext | ||
{ | ||
private readonly ITransactionContext _transactionContext; | ||
|
||
public ReadonlyDecorator(ITransactionContext transactionContext) | ||
{ | ||
_transactionContext = transactionContext; | ||
} | ||
|
||
public void BeginTransaction() => _transactionContext.BeginTransaction(); | ||
|
||
public void CommitTransaction() | ||
{ | ||
RollbackTransaction(); | ||
} | ||
|
||
public void RollbackTransaction() => _transactionContext.RollbackTransaction(); | ||
|
||
|
||
public IDbTransaction CurrentTransaction => _transactionContext.CurrentTransaction; | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
src/abstractions/Backend.Fx/Patterns/UnitOfWork/DbConnectionDecorator.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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Data; | ||
using System.Security.Principal; | ||
using Backend.Fx.Patterns.DependencyInjection; | ||
|
||
namespace Backend.Fx.Patterns.UnitOfWork | ||
{ | ||
/// <summary> | ||
/// Enriches the unit of work to open and close a database connection during lifetime | ||
/// </summary> | ||
public class DbConnectionDecorator : IUnitOfWork | ||
{ | ||
public DbConnectionDecorator(IDbConnection dbConnection, IUnitOfWork unitOfWork) | ||
{ | ||
DbConnection = dbConnection; | ||
UnitOfWork = unitOfWork; | ||
} | ||
|
||
public IUnitOfWork UnitOfWork { get; } | ||
|
||
public IDbConnection DbConnection { get; } | ||
|
||
public ICurrentTHolder<IIdentity> IdentityHolder => UnitOfWork.IdentityHolder; | ||
|
||
public void Begin() | ||
{ | ||
DbConnection.Open(); | ||
UnitOfWork.Begin(); | ||
} | ||
|
||
public void Complete() | ||
{ | ||
UnitOfWork.Complete(); | ||
DbConnection.Close(); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/abstractions/Backend.Fx/Patterns/UnitOfWork/DbTransactionDecorator.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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Security.Principal; | ||
using Backend.Fx.Patterns.DependencyInjection; | ||
using Backend.Fx.Patterns.Transactions; | ||
|
||
namespace Backend.Fx.Patterns.UnitOfWork | ||
{ | ||
/// <summary> | ||
/// Enriches the unit of work to use a database transaction during lifetime. | ||
/// </summary> | ||
public class DbTransactionDecorator : IUnitOfWork | ||
{ | ||
public DbTransactionDecorator(ITransactionContext transactionContext, IUnitOfWork unitOfWork) | ||
{ | ||
TransactionContext = transactionContext; | ||
UnitOfWork = unitOfWork; | ||
} | ||
|
||
public IUnitOfWork UnitOfWork { get; } | ||
|
||
public ITransactionContext TransactionContext { get; } | ||
|
||
public ICurrentTHolder<IIdentity> IdentityHolder => UnitOfWork.IdentityHolder; | ||
|
||
public void Begin() | ||
{ | ||
TransactionContext.BeginTransaction(); | ||
UnitOfWork.Begin(); | ||
} | ||
|
||
public void Complete() | ||
{ | ||
UnitOfWork.Complete(); | ||
TransactionContext.CommitTransaction(); | ||
} | ||
} | ||
} |
83 changes: 0 additions & 83 deletions
83
src/abstractions/Backend.Fx/Patterns/UnitOfWork/DbUnitOfWork.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.