gsoft-inc / wl-extensions-mediatr

MediatR extensions, behaviors and default configuration.
Apache License 2.0
5 stars 0 forks source link

Default Mediator configuration break Scoped services #64

Open Pycnomerus opened 5 months ago

Pycnomerus commented 5 months ago

Describe the bug when using the library default, if you register anything that will be used by a command as scoped. the application crash. with an impossible to resolve configuration error.

this will probably also break typed httpclient.

To Reproduce Steps to reproduce the behavior: when using mediator default registration register a scoped service. try to use it inside any IRequest object.

Expected behavior all type of scopes registration should work without changing the default behaviour. this is especially a concern since it's not an expected behavior, and introduce risk namely to use Typed HttpClient

Screenshots image

Additional context here's a test sample project to reproduce

meziantou commented 5 months ago

The workaround is to set the lifetime to Scoped instead of the default Singleton

builder.Services.AddMediator(configure => configure.Lifetime = ServiceLifetime.Scoped, typeof(Program).Assembly);

It would be nice to re-evaluate the default Lifetime value. It has been set to Singleton for performance reasons. I'm not sure how many projects would be impacted by this change.