I am using the C# MediatR library to implement a mediator pattern to send commands and queries from my controller. As I am new to this pattern so I have been watching some online tutorials where I saw that in some cases the Mediator Query
or Command
classes have been passed as parameters to controller action methods and forwarded as it is to the MediatR while in some tutorials there is a separate view model passed into the controller action methods method, which is first mapped to command or query class and then forwarded to the MediatR.
Which approach is considered better, passing Command/Query to controller action directly or using a view model instead? Couldn't find any relevant answer yet. Any help is highly appeciated
Command being passed into controller action parameter
[HttpPost]
public async Task<IActionResult> Login(LoginUserCommand loginUserCommand)
{
var User = await _meditr.Send(loginUserCommand);
return View();
}
ViewModel used in the controlleraction parameter
[HttpPost]
public async Task<IActionResult> Login(LoginViewModel loginViewModel)
{
var authenticateUserCommand = _mapper.Map<LoginUserCommand>(loginViewModel);
var User = await _meditr.Send(authenticateUserCommand);
return View();
}