-
-
Notifications
You must be signed in to change notification settings - Fork 122
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
Check for mismatch lifestyle scope between service and dependencies #633
Comments
@TheHunter By default it is fine to have Transient for any kind of Scoped consumer. Because Transient means that service is likely stateless and can be recreated whenever it needed. |
hi @dadhi, It would be worth to turn on this rule (WithThrowIfScopedOrSingletonHasTransientDependency) only for some services, what do you think about it? In my case, we apply some strong rules for lifestyles dependencies, but only for external registrations, so for them we would turn off the default rule. |
Huh, ok. |
Hi @dadhi, In fact, i think something like this could be resolved this situation: IContainer container = new Container();
container.Register<IMyService, MyService>(Reuse.Transient, reuse: Rules.WithThrowIfScopedOrSingletonHasTransientDependency());
container.Register<IRootService, RootService>(Reuse.Singleton);
var service = container.Resolve<IRootService>(); What do you think about? Sorry for this delay on this response |
@TheHunter Yes, it kinda makes sense because we already have |
Hi @dadhi , Or if you have other suggestion, It would be appreciated. Thanks in advance. |
@dadhi Yeah, I went to other stuff in meanwhile. I will look into this soon. |
Hi all,
I'm facing with a issue in my code, when I want to check "scopes" between a service and its dependencies, take a this example:
then:
The resolution of IRootService doesn't throw an exception, and I'm wondering if there's a way to check this mismatch of scopes between "root service" and "root dependency".
Thank you in advance.
The text was updated successfully, but these errors were encountered: