Changed domains, configured links between VisaApplication and Applicant,created generic repository and repositories for domains

This commit is contained in:
2024-08-14 18:49:42 +03:00
parent e0f9a0f10f
commit e3d0d05355
35 changed files with 237 additions and 80 deletions

View File

@@ -1,41 +1,36 @@
using System.Reflection;
using Infrastructure.Database.Generic;
using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database
{
public class DbContext : Microsoft.EntityFrameworkCore.DbContext, IWriter, IReader, IUnitOfWork
public class DbContext : Microsoft.EntityFrameworkCore.DbContext, IGenericWriter, IGenericReader, IUnitOfWork
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
}
async Task IWriter.AddAsync<T>(T entity, CancellationToken cancellationToken)
async Task IGenericWriter.AddAsync<T>(T entity, CancellationToken cancellationToken)
{
await AddAsync(entity, cancellationToken);
}
void IWriter.Update<T>(T entity)
void IGenericWriter.Update<T>(T entity)
{
Update(entity);
}
void IWriter.Remove<T>(T entity)
void IGenericWriter.Remove<T>(T entity)
{
Remove(entity);
}
IQueryable<T> IReader.GetAll<T>()
IQueryable<T> IGenericReader.GetAll<T>()
{
return Set<T>();
}
async Task<T?> IReader.GetOneAsync<T>(Guid id, CancellationToken cancellationToken)
where T : class
{
return await Set<T>().FindAsync([id], cancellationToken: cancellationToken);
}
async Task IUnitOfWork.SaveAsync(CancellationToken cancellationToken)
{
await SaveChangesAsync(cancellationToken);