-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
Singleton? #64
Comments
|
IoC can be done without any framework. |
what i mean is that there are many cases without using IoC. : - ) |
Hi @gembin I come out with an implementation of a sort of singleton, that actually is a cache of Config classes. Before you used MyConfig instance = ConfigFactory.create(MyConfig.class); The same way you can use the new MyConfig instance = ConfigCache.getOrCreate(MyConfig.class); The difference is that, when using MyConfig firstFromFactory = ConfigFactory.create(MyConfig.class);
MyConfig secondFromFactory = ConfigFactory.create(MyConfig.class);
// firstFromFactory not same as secondFromFactory
MyConfig firstFromCache = ConfigCache.getOrCreate(MyConfig.class);
MyConfig secondFromCache = ConfigCache.getOrCreate(MyConfig.class);
// firstFromCache same as secondFromCache You can assign an "id" to an instance, MyConfig firstFromCache = ConfigCache.getOrCreate("foo", MyConfig.class);
MyConfig secondFromCache = ConfigCache.getOrCreate("foo", MyConfig.class);
MyConfig thirdFromCache = ConfigCache.getOrCreate("bar", MyConfig.class);
// firstFromCache same as secondFromCache
// thirdFromCache not same as secodFromCache or firstFromCache The |
TODO-list before closing this issue:
|
Great, thx! |
Thanks to you for your help. I'll document this and the other improvements and cut a release asap, so you won't need to build the jar from a snapshot. |
Documented http://owner.aeonbits.org/docs/singleton/ |
Provide a way to define a singleton
Config
objects instead of creating new instances at everycreate()
request.3 possible ways:
@Singleton
annotationConfigFactory.getInstance()
methodAlso provide an example (on a new examples mvn module) to show how to instantiate singleton objects with Spring. See also http://forum.spring.io/forum/spring-projects/container/48256-using-factory-beans-with-factory-method-parameters
The text was updated successfully, but these errors were encountered: