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