There is a method requireBinding(Class) which lets causes the creation of the Injector to fail if the binding is missing.



On 06/24/2013 07:45 AM, Dirk Olmes wrote:
On 06/23/2013 11:56 PM, [email protected] wrote:
I feel this is probably a newbie question.. But I have to admit I'm not
sure how to approach the question:

I have two libraries : LibraryA and LibraryB.
Both are implemented in separated projects (they are two different Maven
artifacts, in my case).
Each of those libraries is based on Guice and provides a Module class
(extending AbstractModule) to bind its required dependencies.

But LibraryA /requires LibraryB/, in that sense that LibraryA makes use
of services provided by LibraryB. Therefore, LibraryB's Module should be
installed, or at least all the dependencies it uses should be binded,
for LibraryA to work. LibraryA is not "standalone" as it cannot work
without LibraryB's dependencies being binded.

My question :

/What is the best way to express, in LibraryA's project, that LibraryB's
Module must be installed?/

- Should I simply document it? Tell the user that he has to install both
an instance of LibraryA's Module and an instance of LibraryB's Module?

- Should I add a LibraryB's Module parameter in LibraryA's constructor
to force code using LibraryA to provide a LibraryB's Module, and then
install it in LibraryA's Module?
I provide an abstract module class in LibraryA that does all the
bindings for LibraryA and  specifies the required bindings as abstract
methods. LibraryB would then subclass this module and add it to the list
of moules while creating the injector.

Example:

LibraryAModule extends AbstractModule {
     configure() {
         bind(SomeLibraryAInterface.class).to(SomeLibraryAImpl.class);
         bind(SomeOtherLibraryAInterface.class).to(getSomeOtherClass());
     }
     abstract Class<SomeOtherLibraryAInterface> getSomeOtherClass();
}

-dirk


--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to