Scopes are surely a way to handle this situation. But Scopes are also hard to get right and they introduce a little "magic" because you need to know that a dependency is scoped. Because if you cache the instance you get from guice in a field it may not be the one you expect at a later state...
Therefore I like to make such things a bit more explicit. In your
case I would create a Class called CurrentWorlds. Make that class
a singleton and have it implement the following 3 methods:
- add(World world)
- remove(World world)
- Collection<World> get()
In you EventListener you can then add and remove worlds as they get loaded and unloaded and in your regular code you can always get the current worlds which is the collection of worlds loaded at that very moment.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/a121d04e-7edc-46fc-b943-72e7427d7cc7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.