2 Commits

Author SHA1 Message Date
mjasin 49b232eaa8 fix: migrate to IDbContextFactory and remove direct AppDbContext from DI 2026-05-05 20:21:57 +02:00
mjasin 3faecbb639 feat: implement structured logging in KnowledgeCoordinator [MN-01] (#10)
Reviewed-on: #10
Co-authored-by: Marek Jasiński <jasins.marek@gmail.com>
Co-committed-by: Marek Jasiński <jasins.marek@gmail.com>
2026-05-05 18:12:09 +00:00
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;