Files

47 lines
1.3 KiB
C#

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