dispose db context from services

This commit is contained in:
Stanley Dimant
2022-08-10 23:39:55 +02:00
parent ffe24b0e71
commit f29edbd1c3
3 changed files with 4 additions and 4 deletions

View File

@@ -51,7 +51,7 @@ namespace MareSynchronosServer
try
{
using var scope = _services.CreateScope();
var dbContext = scope.ServiceProvider.GetService<MareDbContext>()!;
using var dbContext = scope.ServiceProvider.GetService<MareDbContext>()!;
var prevTime = DateTime.Now.Subtract(TimeSpan.FromDays(filesOlderThanDays));

View File

@@ -248,7 +248,7 @@ namespace MareSynchronosServer.Discord
var hashedLodestoneId = BitConverter.ToString(sha256.ComputeHash(Encoding.UTF8.GetBytes(lodestoneId.ToString()))).Replace("-", "");
var db = scope.ServiceProvider.GetService<MareDbContext>();
using var db = scope.ServiceProvider.GetService<MareDbContext>();
// check if discord id or lodestone id is banned
if (db.BannedRegistrations.Any(a => a.DiscordIdOrLodestoneAuth == arg.User.Id.ToString() || a.DiscordIdOrLodestoneAuth == hashedLodestoneId))
@@ -408,7 +408,7 @@ namespace MareSynchronosServer.Discord
private void UpdateStatus(object state)
{
using var scope = services.CreateScope();
var db = scope.ServiceProvider.GetService<MareDbContext>();
using var db = scope.ServiceProvider.GetService<MareDbContext>();
var users = db.Users.Count(c => c.CharacterIdentification != null);

View File

@@ -45,7 +45,7 @@ public class SystemInfoService : IHostedService, IDisposable
MareMetrics.AvailableIOWorkerThreads.Set(ioThreads);
using var scope = _services.CreateScope();
var db = scope.ServiceProvider.GetService<MareDbContext>();
using var db = scope.ServiceProvider.GetService<MareDbContext>();
var users = db.Users.Count(c => c.CharacterIdentification != null);