Implement UoW
This commit is contained in:
15
src/Printbase.Application/IUnitOfWork.cs
Normal file
15
src/Printbase.Application/IUnitOfWork.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Printbase.Domain.Repositories;
|
||||
|
||||
namespace Printbase.Application;
|
||||
|
||||
public interface IUnitOfWork
|
||||
{
|
||||
public IProductRepository ProductRepository { get; }
|
||||
public ICategoryRepository CategoryRepository { get; }
|
||||
public IProductVariantRepository ProductVariantRepository { get; }
|
||||
|
||||
Task SaveAsync();
|
||||
Task BeginTransactionAsync();
|
||||
Task CommitTransactionAsync();
|
||||
Task RollbackTransactionAsync();
|
||||
}
|
||||
36
src/Printbase.Infrastructure/UnitOfWork.cs
Normal file
36
src/Printbase.Infrastructure/UnitOfWork.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Printbase.Application;
|
||||
using Printbase.Domain.Repositories;
|
||||
using Printbase.Infrastructure.Database;
|
||||
|
||||
namespace Printbase.Infrastructure;
|
||||
|
||||
public class UnitOfWork(
|
||||
ApplicationDbContext context,
|
||||
IProductRepository productRepository,
|
||||
IProductVariantRepository productVariantRepository,
|
||||
ICategoryRepository categoryRepository) : IUnitOfWork
|
||||
{
|
||||
public IProductRepository ProductRepository => productRepository;
|
||||
public IProductVariantRepository ProductVariantRepository => productVariantRepository;
|
||||
public ICategoryRepository CategoryRepository => categoryRepository;
|
||||
|
||||
public async Task SaveAsync()
|
||||
{
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task BeginTransactionAsync()
|
||||
{
|
||||
await context.Database.BeginTransactionAsync();
|
||||
}
|
||||
|
||||
public async Task CommitTransactionAsync()
|
||||
{
|
||||
await context.Database.CommitTransactionAsync();
|
||||
}
|
||||
|
||||
public async Task RollbackTransactionAsync()
|
||||
{
|
||||
await context.Database.RollbackTransactionAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user