AppUnitOfWork.cs
2,406 bytes
| 1 | using App.DAL.EF.Repositories; |
|---|---|
| 2 | using App.Domain.Contracts; |
| 3 | using Base.Contracts; |
| 4 | |
| 5 | namespace App.DAL.EF; |
| 6 | |
| 7 | public class AppUnitOfWork : IAppUnitOfWork |
| 8 | { |
| 9 | private readonly AppDbContext _context; |
| 10 | |
| 11 | private ITripRepository? _trips; |
| 12 | private IExpenseRepository? _expenses; |
| 13 | private ITripParticipantRepository? _tripParticipants; |
| 14 | private ITripInvitationRepository? _tripInvitations; |
| 15 | private ISettlementPlanRepository? _settlementPlans; |
| 16 | private ISettlementPaymentRepository? _settlementPayments; |
| 17 | private ITripPollRepository? _tripPolls; |
| 18 | private ITripWishlistItemRepository? _tripWishlistItems; |
| 19 | private ISplitPresetRepository? _splitPresets; |
| 20 | private IBudgetCategoryRepository? _budgetCategories; |
| 21 | private IRefreshTokenRepository? _refreshTokens; |
| 22 | private IUserRepository? _users; |
| 23 | |
| 24 | public AppUnitOfWork(AppDbContext context) |
| 25 | { |
| 26 | _context = context; |
| 27 | } |
| 28 | |
| 29 | public ITripRepository Trips => _trips ??= new TripRepository(_context); |
| 30 | public IExpenseRepository Expenses => _expenses ??= new ExpenseRepository(_context); |
| 31 | public ITripParticipantRepository TripParticipants => _tripParticipants ??= new TripParticipantRepository(_context); |
| 32 | public ITripInvitationRepository TripInvitations => _tripInvitations ??= new TripInvitationRepository(_context); |
| 33 | public ISettlementPlanRepository SettlementPlans => _settlementPlans ??= new SettlementPlanRepository(_context); |
| 34 | public ISettlementPaymentRepository SettlementPayments => _settlementPayments ??= new SettlementPaymentRepository(_context); |
| 35 | public ITripPollRepository TripPolls => _tripPolls ??= new TripPollRepository(_context); |
| 36 | public ITripWishlistItemRepository TripWishlistItems => _tripWishlistItems ??= new TripWishlistItemRepository(_context); |
| 37 | public ISplitPresetRepository SplitPresets => _splitPresets ??= new SplitPresetRepository(_context); |
| 38 | public IBudgetCategoryRepository BudgetCategories => _budgetCategories ??= new BudgetCategoryRepository(_context); |
| 39 | public IRefreshTokenRepository RefreshTokens => _refreshTokens ??= new RefreshTokenRepository(_context); |
| 40 | public IUserRepository Users => _users ??= new UserRepository(_context); |
| 41 | |
| 42 | public IBaseRepository<TEntity> GetRepository<TEntity>() where TEntity : class, IBaseEntity |
| 43 | => new BaseRepository<TEntity>(_context); |
| 44 | |
| 45 | public Task<int> SaveChangesAsync() => _context.SaveChangesAsync(); |
| 46 | } |
| 47 | |