You can affect your provision logic based on bindings, sure.

public class SomeOtherModule {
  @Override protected void configure() {
      bind(ThingThatDependsOnAppProperties.class)
          .toProvider(new Provider<ThingThatDependsOnAppProperties>() {
                 @Inject AppProperties appProperties;

                  @Override public ThingThatDependsOnAppProperties get() {
                          if (appProperties.isSomethingDefined()) {
                                return ...;
                          } else {
                               return ..;
                           }
                  }});
       }
}

You can do the same with a provider method.

But this comes with the caveat that conditional bindings do make for tougher
debugging, and certainly less insightful static analysis.

Fred

On Fri, Jun 17, 2011 at 10:15 AM, Łukasz Osipiuk <[email protected]> wrote:

> Hi!
>
> I have a quick question concerning guice. I guess answer to it is "no"
> but maybe I am wrong, and if so my life would be easier - so here it
> goes.
>
> Is it possible for Module.configure() method to somehow access
> dependencies defined by other modules passed to
> Guice.createInjector()?
>
> Lets assume I have PropertiesModule which exposes implementation of
> @AppProperties Configuration.
>
> Is it possible for SomeOtherModule to get instance of @AppProperties
> Configuration as it was bound by PropertiesModule and perform
> differently depending on what is set in configuration?
>
> If this is possible I would really appreciate a code snippet what is
> correct way of doing this.
>
> Regards, Łukasz Osipiuk
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to