Files
mapo-core/MP.Data/Repository/BaseRepository.cs
T
Samuele Locatelli 45cb6b9f59 Fix integrazione preliminare servizi utils.stats x IOC:
- aggiunta migrations
- correzioni versione ef6 da ef8
- correzioni init varie
2026-04-07 10:30:04 +02:00

48 lines
1.4 KiB
C#

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