Add the ability to retrieve all the instances without non initialised lazy singletons
See original GitHub issueKodein-DI version 6.4.1
Hi,
I have a use case where I want to retrieve all AutoCloseable
from the container, however, without creating lazy instances which haven’t been created yet.
My current code looks like it:
direct.allInstances<AutoCloseable>().forEach {
it.close()
}
The problem here is that it triggers creation of lazy instances, here, only to close them…
If there is a way to do it with current API then I would ask for help. If not then, please, consider it as feature request.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Add the ability to retrieve all the instances without non ...
Hi, I have a use case where I want to retrieve all AutoCloseable from the container, however, without creating lazy instances which haven't...
Read more >Java: Lazy Initializing Singleton - Stack Overflow
You can use an enum as a Singleton enum Singleton { INSTANCE; }. Say your singleton does something undesirable in unit tests, you...
Read more >Implementing the Singleton Pattern in C#
This article deals only with the situation where no parameters are required. Typically a requirement of singletons is that they are created lazily...
Read more >Java Singleton Design Pattern Best Practices with Examples
Lazy initialization method to implement the singleton pattern creates the instance in the global access method. Here is the sample code for ...
Read more >MSC07-J. Prevent multiple instantiations of singleton objects
The instance can be created using lazy initialization, which means that the instance is not created when the class loads but when it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, no need, we will use this issue to follow the possible feature request.
@romainbsl I disagree. I believe there is value in this and I have 2 issues with using Scopes here:
Second problem can be resolved by creating my own Scope but yet again this introduces additional complexity.
My use case is just cleaning up on application close. I think this is a good practice(…) which library such as Kodein-DI would do good in helping spreading. It feels unreasonable to introduce “Scopes” to my application just to do proper cleanup. 😦
It can be generalised to retrieving initialised instances. I think there should be more use cases for this in the wild.
I ask you to reconsider.