C
C#2y ago
kopuo

❔ How to use BeginTransaction in repository from infrastructure

I have this code in CommandHandler (Application layer):
using var transaction = _ProductRepository.BeginTransaction();
using var transaction = _ProductRepository.BeginTransaction();
Repository (Infrastructure layer):
public IDbContextTransaction BeginTransaction()
{
return _dbContext.Database.BeginTransaction();
}
public IDbContextTransaction BeginTransaction()
{
return _dbContext.Database.BeginTransaction();
}
Interface repo (Domain layer):
public interface IProductRepository
{
...
IDbContextTransaction BeginTransaction();
}
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
2 Replies
Anu6is
Anu6is2y ago
why exactly is your domain layer concerned about transactions at all? Are you implementing some sort of domain services or...?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server