Defining controllers
Each controller interacts with a use case that emerged in the analysis stage with its action methods. Action methods do their job by requiring command handlers and query interfaces from the dependency injection engine.
Below is an example of how query objects are required and used:
[HttpGet]
public async Task<IActionResult> Index(
[FromServices] IPackagesListQuery query)
{
var results = await query.GetAllPackages();
var vm = new PackagesListViewModel { Items = results };
return View(vm);
}
Below, instead, is an example of the usage of command handlers:
public async Task<IActionResult> Edit(
PackageFullEditViewModel vm,
[FromServices] ICommandHandler<UpdatePackageCommand> command)
{
if (ModelState.IsValid)
{
await command.HandleAsync(new UpdatePackageCommand(vm));
return RedirectToAction(
nameof(ManagePackagesController.Index));
}
else
return View(vm)...