using Microsoft.EntityFrameworkCore; using System.Threading.Tasks; namespace MP.Data.Repository.IOC { public abstract class BaseRepository : IBaseRepository { #region Protected Fields protected readonly IDbContextFactory _ctxFactory; #endregion Protected Fields #region Protected Constructors protected BaseRepository(IDbContextFactory ctxFactory) => _ctxFactory = ctxFactory; #endregion Protected Constructors #region Protected Methods /// /// Creazione dbcontext per singola transazione /// /// protected async Task CreateContextAsync() => await _ctxFactory.CreateDbContextAsync(); #endregion Protected Methods #if false /// /// Salvataggio dati asincrono /// /// protected async Task SaveChangesAsync(DataLayerContext ctx) => await ctx.SaveChangesAsync() > 0; #endif #if false protected readonly DataLayerContext _dbCtx; protected BaseRepository(DataLayerContext db) => _dbCtx = db; public async Task SaveChangesAsync() => await _dbCtx.SaveChangesAsync() > 0; #endif } }