Having to deal with Guice, I wonder how I should handle dependencies in terms of modules.
In Guice every module is provided by an instance. So if I have a module requiring a certain service it creates the module adding a binding to that service and installs it (binder.install(module)).
Now I have two independent modules that make completely sense to be used independently and both install the same database module.
Using both modules independently no problem arise but what happens if both modules are used in the same application? The database module will be loaded by both modules independently and that can not be correct.
Is there a way to ask the binder if a certain type has already a binding? I can not use getProvider to check on that since all that is returned is a LookupProvider regardless if something is already bind or not.
So how one has to deal with this scenario?
Update:
It seams Guice is unable to provide the following feature:
- Check if a given module was already loaded.
- Check if a given class was already bound.
- Use Providers within the configuration to be able to do distributed configuration (modules being able to configure objects being contributed).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…