Implement UoW

This commit is contained in:
lumijiez
2025-05-27 12:48:12 +03:00
parent 8c81d27d28
commit 89ac29c1fd
2 changed files with 51 additions and 0 deletions

View 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();
}

View 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();
}
}