Skip to content

Commit c73d000

Browse files
committed
Slight optimizations
Adding the ''using'' keyword to handle the IDisposable ApplicationDbContext & EfDeletableEntityRepository Using the .AllAsNoTracking() repository method for when getting the settings count (as it's a read only operation)
1 parent cba793f commit c73d000

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/Services/AspNetCoreTemplate.Services.Data/SettingsService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public SettingsService(IDeletableEntityRepository<Setting> settingsRepository)
1818

1919
public int GetCount()
2020
{
21-
return this.settingsRepository.All().Count();
21+
return this.settingsRepository.AllAsNoTracking().Count();
2222
}
2323

2424
public IEnumerable<T> GetAll<T>()

src/Tests/AspNetCoreTemplate.Services.Data.Tests/SettingsServiceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public async Task GetCountShouldReturnCorrectNumberUsingDbContext()
4343
dbContext.Settings.Add(new Setting());
4444
await dbContext.SaveChangesAsync();
4545

46-
var repository = new EfDeletableEntityRepository<Setting>(dbContext);
46+
using var repository = new EfDeletableEntityRepository<Setting>(dbContext);
4747
var service = new SettingsService(repository);
4848
Assert.Equal(3, service.GetCount());
4949
}

0 commit comments

Comments
 (0)