fix: migrate to IDbContextFactory and remove direct AppDbContext from DI
This commit is contained in:
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using NexusReader.Domain.Entities;
|
using NexusReader.Domain.Entities;
|
||||||
using NexusReader.Infrastructure.Persistence;
|
using NexusReader.Infrastructure.Persistence;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace NexusReader.Infrastructure.Identity;
|
namespace NexusReader.Infrastructure.Identity;
|
||||||
|
|
||||||
@@ -11,12 +12,12 @@ namespace NexusReader.Infrastructure.Identity;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class TokenLimitHandler : AuthorizationHandler<TokenLimitRequirement>
|
public class TokenLimitHandler : AuthorizationHandler<TokenLimitRequirement>
|
||||||
{
|
{
|
||||||
private readonly AppDbContext _dbContext;
|
private readonly IDbContextFactory<AppDbContext> _dbContextFactory;
|
||||||
private readonly UserManager<NexusUser> _userManager;
|
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;
|
_userManager = userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,8 @@ using (var scope = app.Services.CreateScope())
|
|||||||
{
|
{
|
||||||
var services = scope.ServiceProvider;
|
var services = scope.ServiceProvider;
|
||||||
var logger = services.GetRequiredService<ILogger<Program>>();
|
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 maxRetries = 5;
|
||||||
int delayMs = 2000;
|
int delayMs = 2000;
|
||||||
|
|||||||
Reference in New Issue
Block a user