I have the following MediatR behavior:
public class FailFastRequestBehavior<TRequest, TResponse>
: IPipelineBehavior<TRequest, TResponse>
where TRequest : IRequest<TResponse>
where TResponse : BaseResponse
and is registered in default ASP.NET Core DI container like this:
services.AddScoped(
typeof(IPipelineBehavior<,>),
typeof(FailFastRequestBehavior<,>));
which handles commands like this:
public class Command: IRequest<BaseResponse>
This works great, but the BaseResponse class has a property that can contain the command result, and this way it's typed as object, which is not great.
And I would like to make the BaseResponse Generic, so the commands would be something like:
public class Command: IRequest<BaseResponse<MyObject>>
How could I change the behavior signature to support this and then properly register it? If it's even possible...
I tried several things, but the one that seems more reasonable for me is this:
public class FailFastRequestBehavior<TRequest, TResponse, TValue>
: IPipelineBehavior<TRequest, TResponse>
where TRequest : IRequest<TResponse>
where TResponse : BaseResponse<TValue>
But then my behavior has 3 generic parameters and the MediatR interface has only 2, and I cannot register it in the DI container.
Any suggestions?