I think perhaps you want to reconsider how you do this because the lifecycle
of a module versus the lifecycle of an injector is going to make your
current design slightly infeasible.  That is, you can be injected something
until an injector is created, which necessarily happens after all 'bind'
statements are processed.

>From what I garner, you're looking to have your properties bound and then
injected as dependencies into other bindings.

You can always effect those ends with something like:

    bind(DataSource.class)
      .toProvider(new Provider<DataSource>() {
            @Inject @Named("data.source")
             private String dataSource

            @Override public DataSource get() {
               return fromJndi(
                   DataSource.class, dataSource)).get();
            }
     });

obviously that's not the most elegant solution, but the point is that you
can inject your properties into a provider (or provider method) if other
bindings are dependent on them.  that is how to skirt the lifecycle issue.

-Fred


On Tue, Oct 26, 2010 at 4:12 PM, Filipe Sousa <[email protected]> wrote:

> I'm posting this again (my first post got lost).
>
> I'm trying to configure my ServletModule using Names.bindProperties()
> doing the following:
>
> public class FooModule extends ServletModule {
>   @Inject @Named("data.source") private String dataSource;
>
>   protected void configureServlets() {
>     Names.bindProperties(binder(), loadProperties());
>     requestInjection(this);
>     bind(Context.class).to(InitialContext.class);
>     bind(DataSource.class)
>       .toProvider(fromJndi(DataSource.class, dataSource));
>   }
> }
>
> I thought the requestInjection(this) would load the property
> "data.source"
> into dataSource but no, the dataSource remains null.
>
> What is the best way to have the properties available in each module?
>
> I'm using guice trunk (r1275)
>
> Thank you
>
> --
> 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]<google-guice%[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