On 11 December 2011 17:47, Simone Tripodi <[email protected]> wrote:
> I don't know that's why I am asking, it does work with constants! > Type conversion only applies to constant bindings, ie. those using bindConstant()...to(...) or bind(...)...toInstance(...) - I believe this was a design decision by Bob, et al. See convertConstantStringBinding in InjectorImpl.java for the exact logic, but basically Provider<String> bindings will fail the isConstant() check and will be ignored. > -Simo > > http://people.apache.org/~simonetripodi/ > http://simonetripodi.livejournal.com/ > http://twitter.com/simonetripodi > http://www.99soft.org/ > > > > On Sun, Dec 11, 2011 at 6:29 PM, Fred Faber <[email protected]> wrote: > > how does the code know the injection point requires a URI type? > > > > On Dec 11, 2011 10:57 AM, "Simone Tripodi" <[email protected]> > wrote: > >> > >> Hi all guys, > >> > >> I've been maintaining a Guice extension, trying to expand the Names > >> class adding properties expansions behavior, i.e. a properties file > >> like > >> > >> project.name=google-guice > >> project.url=http://code.google.com/p/${project.name}/ > >> > >> would bind properties in the way that when requesting the injection of > >> > >> @Named( "project.url" ) String projectUrl; > >> > >> Guice resolves correctly the variables. > >> > >> My issue comes with missing bindings, because properties binding works > >> with a Provider<String> that resolves variables from the Injector: > >> > >> LinkedBindingBuilder<String> builder = bind( get( > >> String.class, named( name ) ) ); // identical to Names class > >> > >> PropertiesResolverProvider formatter = new > >> PropertiesResolverProvider( value ); > >> if ( formatter.containsKeys() ) > >> { > >> builder.toProvider( guicify( formatter ) ); > >> } > >> else > >> { > >> builder.toInstance( value ); > >> } > >> > >> when binding to a constant, using `toInstance( value )`, type > >> conversion works like a charm; when binding to a provider, using > >> `toProvider( guicify( formatter ) )`, it the target injection point > >> would be > >> > >> @Named( "project.url" ) URI projectUrl; > >> > >> Guice throws an exception: > >> > >> No implementation for java.net.URI annotated with > >> @com.google.inject.name.Named(value=project.url) was bound. > >> > >> Can anyone kindly help me on understanding how to provide missing > binding? > >> For everyone interested on read the source code, it is OSS on GitHub[1]. > >> > >> Many thanks in advance, all the best! > >> -Simo > >> > >> [1] https://github.com/99soft/rocoto > >> > >> http://people.apache.org/~simonetripodi/ > >> http://simonetripodi.livejournal.com/ > >> http://twitter.com/simonetripodi > >> http://www.99soft.org/ > >> > >> -- > >> 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. > > -- > 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. > > -- Cheers, Stuart -- 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.
