Giter Club home page Giter Club logo

Comments (5)

zachpainter77 avatar zachpainter77 commented on July 17, 2024 1

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.

from mediatr.

zachpainter77 avatar zachpainter77 commented on July 17, 2024

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, SomeRequestType<T1, T2, T3, etc.. TN> with no constraints makes it very complex to compute every single possible concrete combination of SomeRequestTypeHandler<SomeRequestType<T1, T2, T3, etc.. TN>>.

In the meantime a workaround is to:

  1. revert back to previous version
    or
  2. update your add mediator call configuration to provide a type evaluator that will tell mediator to skip trying to register your generic request handlers. (this will not affect your manual registrations)
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)

from mediatr.

rbasniak avatar rbasniak commented on July 17, 2024

Thanks for the reply, for me, the workaround is enough for my needs, so I am closing this issue.

from mediatr.

sorbonad avatar sorbonad commented on July 17, 2024

Hello, the improvement / fix mentioned is something that is going to be released soon or it will take time? thanks

from mediatr.

sorbonad avatar sorbonad commented on July 17, 2024

Alright, thank you @zachpainter77

from mediatr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.