-
Notifications
You must be signed in to change notification settings - Fork 78
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
Ease the creation of singleton components in factory #211
Comments
You can already do something with LocalMachines.threadLocal()
.set(ComponentModule.ENV_APP_NAME, "test")
.set("tempEventBus", new EventBus());
Factory factory = Factory.builder()
.addLocalMachines(LocalMachines.threadLocal())
.build();
// do stuff
LocalMachines.threadLocal().clear(); I think the LocalMachines API is pretty fine for that, the problem is that LocalMachines are always put in a context (a named context or a thread local) and therefore must be cleared. Maybe by adding a way to get a fresh and disposable instance of Factory factory = Factory.builder()
.addLocalMachines(LocalMachines.local()
.set(ComponentModule.ENV_APP_NAME, "test")
.set("tempEventBus", new EventBus()))
.build(); Maybe we could even allow the easy creation of a Factory from Factory factory = LocalMachines.local()
.set(ComponentModule.ENV_APP_NAME, "test")
.set("tempEventBus", new EventBus())
.buildFactory(); WDYT? |
I didn't thought of using the local machine API. I'm using it quite often, but more in a way of ensuring the existence of components or overriding components, in unit tests, when the factory is created somewhere else in the system. I like the two solutions, indeed having to clear the thread local when you are the creator of the factory is not convenient, so the instance of a |
+1 with Augustin :-) Le jeu. 30 juil. 2015 09:29, a-peyrard notifications@github.com a écrit :
|
To create simple factories, especially in unit tests, I often create the factory with a bunch of singleton factory machines like this:
I think it might be nice to add a method to the factory builder, permitting to do something like this:
WDYT ?
The text was updated successfully, but these errors were encountered: