C#C
C#4y ago
2 replies
kopuo.

❔ How to use BeginTransaction in repository from infrastructure

I have this code in CommandHandler (Application layer):
using var transaction = _ProductRepository.BeginTransaction();

Repository (Infrastructure layer):
public IDbContextTransaction BeginTransaction()
{
  return _dbContext.Database.BeginTransaction();
}

Interface repo (Domain layer):
public interface IProductRepository
{
  ...
  IDbContextTransaction BeginTransaction();
}

I don't want to use IDbContextTransaction in the domain layer because it uses a reference to Microsoft.EntityFrameworkCore.Storage and I would like to avoid such in this layer. Is there any neat way to use BeginTransaction in some repository? I also don't want to directly apply dbContext in my CommandHandler, but do this by infrastructure layer
Was this page helpful?