Skip to content

Commit

Permalink
db context made protected
Browse files Browse the repository at this point in the history
  • Loading branch information
lordspinach authored and Insei committed Apr 5, 2024
1 parent b7f2efc commit 4aaf4d5
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public class KirelGenericEntityFrameworkRepository<TKey, TEntity, TDbContext> :
where TKey : IComparable, IComparable<TKey>, IEquatable<TKey>
where TDbContext : DbContext
{
private readonly TDbContext _dbContext;
/// <summary>
/// Db context
/// </summary>
protected readonly TDbContext DbContext;
/// <summary>
/// Reader field for read access
/// </summary>
Expand All @@ -30,15 +33,15 @@ protected virtual IQueryable<TEntity> Reader
/// </summary>
protected virtual DbSet<TEntity> Writer
{
get => _dbContext.Set<TEntity>();
get => DbContext.Set<TEntity>();
}
/// <summary>
/// GenericRepository constructor
/// </summary>
/// <param name="context">DbContext</param>
public KirelGenericEntityFrameworkRepository(TDbContext context)
{
_dbContext = context;
DbContext = context;
}
/// <summary>
/// Add new Entity
Expand All @@ -48,8 +51,8 @@ public KirelGenericEntityFrameworkRepository(TDbContext context)
public async Task<TEntity> Insert(TEntity entity)
{
Writer.Add(entity);
_dbContext.Entry(entity).State = EntityState.Added;
await _dbContext.SaveChangesAsync();
DbContext.Entry(entity).State = EntityState.Added;
await DbContext.SaveChangesAsync();
return entity;
}
/// <summary>
Expand All @@ -74,7 +77,7 @@ public async Task Delete(TKey id)
if (entity == null)
throw new KeyNotFoundException($"Entity with specified id {id} was not found");
Writer.Remove(entity);
await _dbContext.SaveChangesAsync();
await DbContext.SaveChangesAsync();
}
/// <summary>
/// Updating entity
Expand All @@ -84,8 +87,8 @@ public async Task Delete(TKey id)
public async Task<TEntity> Update(TEntity entity)
{
Writer.Attach(entity);
_dbContext.Entry(entity).State = EntityState.Modified;
await _dbContext.SaveChangesAsync();
DbContext.Entry(entity).State = EntityState.Modified;
await DbContext.SaveChangesAsync();
return entity;
}
/// <summary>
Expand Down

0 comments on commit 4aaf4d5

Please sign in to comment.