Могу ли я вызвать QueryHandler/CommandHandler в другом CommandHandler в CQRS?C#

Место общения программистов C#
Ответить
Anonymous
 Могу ли я вызвать QueryHandler/CommandHandler в другом CommandHandler в CQRS?

Сообщение Anonymous »

Я работаю над проектом веб-API ASP.NET Core 6.0. Я использую шаблон проектирования CQRS.
Я хочу обновить таблицу авиакомпаний (EF Core с приоритетом кода). Итак, сначала мне нужно найти идентификатор авиакомпании.
У меня есть GetAirlineByIdQueryHandler.cs
public record GetAirlineByIdQuery(int Id, bool LoadOverview = true) : IRequest;

public class GetAirlineByIdQueryHandler : IRequestHandler
{
public async Task Handle(GetAirlineByIdQuery request, CancellationToken cancellationToken)
{
var query = _techneDbContext.Airline
.Include(d => d.X)
.Include(d => d.Y)
.Include(d => d.Z)

.AsQueryable();

if (request.LoadOverview)
{
query = query.Include(d => d.Overview);
}

var airline = await query.FirstOrDefaultAsync(d => d.Id == request.Id);

if (airline == null)
{
throw new NotFoundException(nameof(Airline), request.Id);
}

return airline;
}
}

UpdateAirlineCommand.cs
public class UpdateAirlineCommand : AirlineUpdateDto, IRequest
{
public int Id { get; set; }
}

public class UpdateAirlineCommanddHandler : IRequestHandler
{
// removed constructor

public async Task Handle(UpdateAirlineCommand request, CancellationToken cancellationToken)
{
// To update I have find the the id is there or not?
// Can I call GetAirlineByIdQueryHandler here or do I need to copy the query and paste it here
}
}


Подробнее здесь: https://stackoverflow.com/questions/708 ... er-in-cqrs
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»