Refactor repository pattern and modernize codebase
Removed `SaveChangesAsync` from `IRepository` and `Repository` to centralize transaction management in `DbContext`. Updated `CfgProfileRepository` to use `Context` property instead of `_context`. Refactored `Repository` class to use C# 9.0 record-like constructor syntax and replaced private fields with properties (`Context`, `DbSet`, `Mapper`). Replaced `Any()` with `Count == 0` for null checks and updated `FindAsync` to use C# 11 object array syntax. Added conditional compilation for framework-specific differences. These changes improve readability, consistency, and leverage modern C# features.
This commit is contained in:
@@ -31,7 +31,7 @@ namespace ECMJobRunner.Infrastructure.Repositories
|
||||
/// </summary>
|
||||
public async Task<CfgProfile?> GetByIdWithSqlJobsAsync(long id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _context.CfgProfiles
|
||||
return await Context.CfgProfiles
|
||||
.Include(p => p.SqlJobs)
|
||||
.FirstOrDefaultAsync(p => p.Id == id, cancellationToken);
|
||||
}
|
||||
@@ -41,7 +41,7 @@ namespace ECMJobRunner.Infrastructure.Repositories
|
||||
/// </summary>
|
||||
public async Task<List<CfgProfile>> GetAllActiveWithSqlJobsAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _context.CfgProfiles
|
||||
return await Context.CfgProfiles
|
||||
.Include(p => p.SqlJobs)
|
||||
.Where(p => p.Active)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user