fix: resolve DI failure in GetUserProfileQueryHandler by using IDbContextFactory
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user