C
C#9mo ago
TYoemtais.z

❔ Weird issue with MediaR pipeline.

I have such a typical pipeline UnhandledExceptionBehaviour, which executes before executing command. And it's works fine, for example for this kind of request:
[HttpPost("addnewguest")]
public async Task<ActionResult<string>> AddNewGuest(CreateGuestCommand command)
{
return await Mediator.Send(command);
}
[HttpPost("addnewguest")]
public async Task<ActionResult<string>> AddNewGuest(CreateGuestCommand command)
{
return await Mediator.Send(command);
}
But when there is no content, this pipeline is omitted. For example:
[HttpPost("mergeguests")]
public async Task<ActionResult> MergeGuests(MergeGuestsCommand command)
{
await Mediator.Send(command);

return NoContent();
}
[HttpPost("mergeguests")]
public async Task<ActionResult> MergeGuests(MergeGuestsCommand command)
{
await Mediator.Send(command);

return NoContent();
}
It is the request:
public record MergeGuestsCommand : IRequest
public record MergeGuestsCommand : IRequest
There used to be a
public record MergeGuestsCommand : IRequest<Unit>
public record MergeGuestsCommand : IRequest<Unit>
, but I read to remove <Unit> in the new version of MediaR and it caused the code to no longer work as it used to. Why?
2 Replies
TYoemtais.z
TYoemtais.z9mo ago
Ok, found the issue. In new version, there is need to change:
public class UnhandledExceptionBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : IRequest<TResponse>
public class UnhandledExceptionBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : IRequest<TResponse>
To:
public class UnhandledExceptionBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : IBaseRequest
public class UnhandledExceptionBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : IBaseRequest
Accord
Accord9mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.