Я работаю над проектом веб-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
Могу ли я вызвать QueryHandler/CommandHandler в другом CommandHandler в CQRS? ⇐ C#
Место общения программистов C#
1731852563
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
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/70831902/can-i-call-queryhandler-commandhandler-in-another-commandhandler-in-cqrs[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия