Review schema gestione repository x evitare concorrezza contesto DbContext

This commit is contained in:
Samuele Locatelli
2026-03-17 09:15:52 +01:00
parent afaa9a5516
commit f70814d444
37 changed files with 544 additions and 461 deletions
@@ -1,14 +1,46 @@
namespace EgwCoreLib.Lux.Data.Repository
using Microsoft.EntityFrameworkCore;
namespace EgwCoreLib.Lux.Data.Repository
{
public abstract class BaseRepository : IBaseRepository
{
protected readonly DataLayerContext _dbCtx;
protected BaseRepository(DataLayerContext db) => _dbCtx = db;
#region Protected Fields
protected readonly IDbContextFactory<DataLayerContext> _ctxFactory;
#endregion Protected Fields
#region Protected Constructors
protected BaseRepository(IDbContextFactory<DataLayerContext> ctxFactory)
=> _ctxFactory = ctxFactory;
#endregion Protected Constructors
#region Protected Methods
/// <summary>
/// Creazione dbcontext per singola transazione
/// </summary>
/// <returns></returns>
protected async Task<DataLayerContext> 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
}
}
}