Skip to content
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

Default Mediator configuration break Scoped services #64

Open
Pycnomerus opened this issue Apr 10, 2024 · 1 comment
Open

Default Mediator configuration break Scoped services #64

Pycnomerus opened this issue Apr 10, 2024 · 1 comment

Comments

@Pycnomerus
Copy link

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants