fix: migrate to IDbContextFactory and remove direct AppDbContext from DI

This commit is contained in:
2026-05-05 20:21:57 +02:00
parent 3faecbb639
commit 49b232eaa8
2 changed files with 6 additions and 4 deletions
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using NexusReader.Domain.Entities;
using NexusReader.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
namespace NexusReader.Infrastructure.Identity;
@@ -11,12 +12,12 @@ namespace NexusReader.Infrastructure.Identity;
/// </summary>
public class TokenLimitHandler : AuthorizationHandler<TokenLimitRequirement>
{
private readonly AppDbContext _dbContext;
private readonly IDbContextFactory<AppDbContext> _dbContextFactory;
private readonly UserManager<NexusUser> _userManager;
public TokenLimitHandler(AppDbContext dbContext, UserManager<NexusUser> userManager)
public TokenLimitHandler(IDbContextFactory<AppDbContext> dbContextFactory, UserManager<NexusUser> userManager)
{
_dbContext = dbContext;
_dbContextFactory = dbContextFactory;
_userManager = userManager;
}
+2 -1
View File
@@ -135,7 +135,8 @@ using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
var logger = services.GetRequiredService<ILogger<Program>>();
var dbContext = services.GetRequiredService<NexusReader.Infrastructure.Persistence.AppDbContext>();
var dbContextFactory = services.GetRequiredService<IDbContextFactory<NexusReader.Infrastructure.Persistence.AppDbContext>>();
using var dbContext = await dbContextFactory.CreateDbContextAsync();
int maxRetries = 5;
int delayMs = 2000;