-
Notifications
You must be signed in to change notification settings - Fork 67
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
DefaultServiceLifetime.Transient registers Mediator as transient too as opposed to ReadMe #127
Comments
Not sure what the expected behaviour should be, but for the time being you could you preemptively add the services before calling |
Thanks for the reminder (sometimes I forget the easy workarounds)!
Maybe provide another option to configure that lifetime too? Something like public sealed class MediatorOptions
{
public string Namespace { get; set; } = "Mediator";
public ServiceLifetime MediatorServiceLifetime { get; set; } = ServiceLifetime.Singleton;
public ServiceLifetime HandlerServiceLifetime { get; set; } = ServiceLifetime.Scoped;
} Renaming the |
Hmm I think it used to be as documented atleast, maybe there was a bug at some point that required this. Don't remember but I'll try to dig into it |
Oo yes apparantly this was a bug that was fixed: #73 I'll have to update the README in any case, thanks! |
Thanks for finding the PR. Would it be possible that instead of #73 for the activation a new servce cope is created for the handlers? |
Right now, if configured as transient, but used/injected from ASP.NET Core, scoped instances of services could (depending on how Can I ask what is problematic about this behavior, is it the memory allocation? Or is initialization expensive? I honestly have not looked too much at perf for transient configuration apart from that one optimization which had to be removed |
Yep, I understand, and that's a very valid point.
Yes, but TBH there are larger allocations (not from Mediator) that should be elided first. So more or less a micro-optimization. For the scenario w/ ASP.NET Core's request there are some way to differentiate if it's the root scope or not (at simplest, just a reference compare), but now I believe that this adds more overhead and for sure complicates the SGen very much. Thus the current (documented) behavior is fine for me. |
ReadMe states
source
but I see the code generated as
Transient
for the Mediator too (version 2.1.7):As
DefaultServiceLifetime
->ServiceLifetime
in #24 is that a documentation issue (i.e. need to update the ReadMe -- I can send a PR) and / or is the behavior by intention?I'd really like to have the Mediator registered as singleton, while the handlers, etc. be transient / scoped.
The text was updated successfully, but these errors were encountered: