-
Notifications
You must be signed in to change notification settings - Fork 89
Error: "Request violates the constrain of type TRequest..." on pipelines #91
Comments
Unless you're on the latest version of MS DI, this won't work. MS DI only with the latest version supports generic constraints |
I'm running this on an asp.net core 3.1 app. I'm not directly linking MS DI. Also, this was working fine with the previous version of MediatR (v8)... |
Are you using the vanilla container? MS DI would have choked on this every time up until 5.0, this is highly surprising this worked out-of-the-box. I added the PR to MS DI for this exact scenario. |
The generic constraints were added for .net 5.0. It will "work" in previous versions of dotnet core as long as all of your commands sent through the pipeline match the constraint. The moment you try to send a command that violates the constraint you will get this message. Are you sure the exact scenario you are trying worked prior to the MediatR upgrade? |
Right now I have in front of me a branch of my project with M8 that it is working fine (with the above definitions) and switching to the branch where I upgrade MediatR, I'm getting the above error. So yes, I can confirm that it was working (magically, maybe?) and now it is not. @jbogard I'm not sure what you mean by vanilla container. I guess the answer is yes, as I'm using the registry container ms provides me in the startup.cs ( |
If you can create a minimal repro of the problem I would be happy to check it out. I have my own test project using M8.1 and I get this exception on dotnet core 3.1 when I have two behaviors registered with exclusive constraints. |
@lilasquared I will try. Please note that I have only one behavior. Right now I solved this by removing the constraints and checking for the interface implementation inside the handler. |
@CheloXL sorry yeah, one behavior with exclusive constraints. in my example I have and I get the exception when I attempt to send |
I just upgraded MediatR and now my project doesn't works as intented.
I have a request
AccessTokenAdminCommand : IRequest<OperationResult<string>>
. I also have a pipeline defined asPipelineCommands<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : IUserIdDescriptor where TResponse : class
Previously, this was working fine (the pipeline was not trying to intercept my command, since
AccessTokenAdminCommand
doesn't implementsIUserIdDescriptor
).Now, MediatR is trying to run the command through the pipeline, throwing:
I'm opening the issue here since this seems to be a problem with the MS DI and the way you find instances of IPipelineBehavior.
The text was updated successfully, but these errors were encountered: