-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't register generic handlers in latest version #1043
Comments
Yes, this is a bug with the new version. I am working on a fix and have just about got it.. However need some input from others in regards to some limits to put on these features. The issues arise from the new updated support of generic handlers to not support generic requests with more than one type parameter. The issue is fixed in my local version however this also let's users define too many types which could cause mediatR to hang in service registration as you could understand if there were too many type parameters each with it's own number of types that can close that type parameter. I'm trying to come up with a solution that will register handlers like your's above and will not let the user essentially soft lock their app when being too vague with parameters. For example, In the meantime a workaround is to:
builder.Services.AddMediatR(config => {
config.TypeEvaluator = x => !x.ContainsGenericParameters;
config.RegisterServicesFromAssemblies(assemblies);
}); by setting up mediatR this way you tell it to only try to register handler types that do not contain generic type parameters. (The default behavior of previous versions) |
Thanks for the reply, for me, the workaround is enough for my needs, so I am closing this issue. |
Hello, the improvement / fix mentioned is something that is going to be released soon or it will take time? thanks |
Hello @sorbonad There is an active pull request that fixes the issue.. It might take some time to get merged. Until then, you can implement this workaround: builder.Services.AddMediatR(config => {
//add this line to filter out handlers that contain generic parameters.
//This will effectively turn off the newly added feature.
config.TypeEvaluator = x => !x.ContainsGenericParameters;
config.RegisterServicesFromAssemblies(assemblies);
}); Or roll back MediatR to the previous version. |
Alright, thank you @zachpainter77 |
Hi,
I have some request/handlers like this:
The
AddMediatR
method wasn't able to identify these handlers so I used to register them manually:services.AddScoped<IRequestHandler<CreateScaffoldingResourceOn<T1, T2, T3>.Request, CommandResponse>, CreateScaffoldingResourceOn<T1, T2, T3>.Handler>();
This worked fine until I updated to 12.3.0. Now I am getting the following exception in the
AddMediatR
method:If I comment these handlers from my assembly, then my application starts again, so the problem is definitely related to registration changes in the latest version.
Is this a bug or an intended change? If so, what would be the suggestion to keep using the latest version?
The text was updated successfully, but these errors were encountered: