-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Question about singleton scope in shared container #92
Comments
Yep. That's a fairly specific bug in regard to singletons in SharedContainer being resolved across multiple container instances and multiple container classes. I'll look into it. At this point in time defaultScope is container-based. Any resolution from a container uses that container's default scope. Your best bet there is simply to mark the service with .singleton. |
I tried add .singleton to service in SharedContainer but it still inits twice. Behaviour stayed the same. |
As mentioned this is a bug. The "Your best bet there is simply to mark the service with .singleton." is the answer to the second question you asked. Since "SharedContainer" is virtual, there's no associated defaultScope, so each definition would need to marked as singleton. That approach, however, won't work until the bug is fixed for this specific use case. |
It's not an official release yet, but you can pull the main branch and see if this corrects the problem. |
Yes, it's helped, service init one time thank you |
Hi there, I have updated on version 2.1.1 and still facing problem from https://github.com/hmlongco/Factory/issues/86 if I have my singleton service in SharedConatiner and it used in other services and containers and it injects somewhere else in my code - service initing twice. First time when it inits for other service, second time when injects. For all my containers I use
manager.defaultScope = .singleton
. Could you please explain how to fix that?And I have another question. How can I setup default scope for SharedConatiner services?
The text was updated successfully, but these errors were encountered: