using System.Reflection; using ApplicationLayer.InfrastructureServicesInterfaces; using Infrastructure.Database.Generic; using Microsoft.EntityFrameworkCore; namespace Infrastructure.Database; public class DatabaseContext(DbContextOptions opts) : DbContext(opts), IGenericWriter, IGenericReader, IUnitOfWork { protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); } async Task IGenericWriter.AddAsync(T entity, CancellationToken cancellationToken) { await AddAsync(entity, cancellationToken); } void IGenericWriter.Update(T entity) { Update(entity); } void IGenericWriter.Remove(T entity) { Remove(entity); } IQueryable IGenericReader.GetAll() { return Set(); } async Task IUnitOfWork.SaveAsync(CancellationToken cancellationToken) { await SaveChangesAsync(cancellationToken); } }