jbogard/MediatR

Implement IRequest, how to enter Behavior

snowchenlei opened this issue · 1 comments

Implement IRequest, how to enter Behavior

services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));

public record CreateRequest(string Name) : IRequest { }

public class CreateRequestHandler : IRequestHandler<CreateRequest> {}

The above code does not execute ValidationBehavior.Handle

I know.The problem lies in the definition of ValidationBehavior.The problem is with the generic constraints of the ValidationBehavior parameter.
A common definition should be as follows:

public class ValidationBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : notnull