Skip to content

Commit

Permalink
IDbConnection instead of DbConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
marcwittke committed Dec 18, 2019
1 parent 636396e commit 1741fa0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Data;
using System.Data.Common;
using Backend.Fx.Logging;

namespace Backend.Fx.Patterns.UnitOfWork
Expand All @@ -11,11 +10,11 @@ public class TransactionContext : IDisposable
private IDisposable _transactionLifetimeLogger;
private readonly bool _shouldHandleConnectionState;

public DbConnection Connection { get; }
public IDbConnection Connection { get; }

public DbTransaction CurrentTransaction { get; private set; }
public IDbTransaction CurrentTransaction { get; private set; }

public TransactionContext(DbConnection connection)
public TransactionContext(IDbConnection connection)
{
Connection = connection;
ConnectionState connectionState = Connection.State;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using System.Data.Common;
using System.Data;
using System.Security.Principal;
using Backend.Fx.Patterns.DependencyInjection;

namespace Backend.Fx.Patterns.UnitOfWork
{
public class UnitOfWorkTransactionDecorator : IUnitOfWork
{
public UnitOfWorkTransactionDecorator(DbConnection dbConnection, IUnitOfWork unitOfWork)
public UnitOfWorkTransactionDecorator(IDbConnection dbConnection, IUnitOfWork unitOfWork)
{
UnitOfWork = unitOfWork;
TransactionContext = new TransactionContext(dbConnection);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Data;
using System.Data.Common;
using Backend.Fx.Patterns.UnitOfWork;
using Microsoft.EntityFrameworkCore;
Expand All @@ -8,15 +9,15 @@ public class EfUnitOfWorkTransactionDecorator<TDbContext> : UnitOfWorkTransactio
{
private readonly EfUnitOfWork<TDbContext> _unitOfWork;

public EfUnitOfWorkTransactionDecorator(DbConnection dbConnection, EfUnitOfWork<TDbContext> unitOfWork) : base(dbConnection, unitOfWork)
public EfUnitOfWorkTransactionDecorator(IDbConnection dbConnection, EfUnitOfWork<TDbContext> unitOfWork) : base(dbConnection, unitOfWork)
{
_unitOfWork = unitOfWork;
}

public override void Begin()
{
base.Begin();
_unitOfWork.DbContext.Database.UseTransaction(TransactionContext.CurrentTransaction);
_unitOfWork.DbContext.Database.UseTransaction((DbTransaction) TransactionContext.CurrentTransaction);
}
}
}
2 changes: 1 addition & 1 deletion tests/Backend.Fx.EfCorePersistence.Tests/DbSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static DbTransaction GetDbTransaction(this IUnitOfWork unitOfWork)
{
if (unitOfWork is UnitOfWorkTransactionDecorator transactionDecorator)
{
return transactionDecorator.TransactionContext.CurrentTransaction;
return (DbTransaction) transactionDecorator.TransactionContext.CurrentTransaction;
}

throw new InvalidOperationException();
Expand Down

0 comments on commit 1741fa0

Please sign in to comment.