fix: resolve DI failure in GetUserProfileQueryHandler by using IDbContextFactory

This commit is contained in:
2026-05-10 18:18:35 +02:00
parent b456194ea1
commit 652e74c2f5
@@ -8,16 +8,17 @@ namespace NexusReader.Application.Queries.User;
public class GetUserProfileQueryHandler : IRequestHandler<GetUserProfileQuery, Result<UserProfileDto>>
{
private readonly AppDbContext _dbContext;
private readonly IDbContextFactory<AppDbContext> _dbContextFactory;
public GetUserProfileQueryHandler(AppDbContext dbContext)
public GetUserProfileQueryHandler(IDbContextFactory<AppDbContext> dbContextFactory)
{
_dbContext = dbContext;
_dbContextFactory = dbContextFactory;
}
public async Task<Result<UserProfileDto>> Handle(GetUserProfileQuery request, CancellationToken cancellationToken)
{
var profile = await _dbContext.Users
using var dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
var profile = await dbContext.Users
.Where(u => u.Id == request.UserId)
.Select(u => new UserProfileDto
{