At first we have a properties file 'config.properties':
test.key=test value
And we want to inject this value like this:
@Inject @Config( Property.TEST_KEY ) private String injectedValue;
We need to load contents of file 'config.properties' into java.util.Properties and pass it to Config module:
Properties props = new Properties(); props.load(...); Module configModule = new ConfigModule( props, Property.values() );
... and injecting:
Injector injector = Guice.createInjector( configModule ); TestClass testClass = injector.getInstance( TestClass.class ); String injectedValue = testClass.getInjectedValue();
injected value will be 'test value'...
--
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 google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/28f51f39-e29a-4f9c-a9ea-c70749adb8f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
A unit test may be worth a thousand words here, so:
--
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 google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/1378b3bb-908f-42a1-8272-728819321a30%40googlegroups.com.
Whats wrong with Names.bindProperties(binder, myProps) provided by Guice? Isn't that effectively the same?