On Thursday, April 25, 2013 8:04:49 AM UTC+2, mmonti wrote:
Hi guys,I really appreciate your replies. I took a look at both solutions Tim's micro-fwk and magic-config, but unfortunately I couldn't make it work, and also I am not sure if what i need. To be honest I think that I am pretty lost since I tried different ways to do it without success. Ill try to describe what "I think" my problem is and let me know if I am wrong.The thing is, I need to bind a constant to a String value: bindConstant().annotatedWith(Db4Objects.class).to( <value-taken-from-properties> ).That value should be passed to the module by the constructor or injected. BTW, I am using Names.bindProperties(...) to bind my config.properties files.So, my persistence module looks like:
public class PersistenceModule extends AbstractModule {
@Inject @Named("config.db4o.database")private String database;@Overrideprotected void configure() {install(PersistenceService.usingDb4o().across(UnitOfWork.REQUEST).buildModule());bindConstant().annotatedWith(Db4Objects.class).to(database);}}
I wonder if you couldn't use:
bind(String.class).annotatedWith(Db4Objects.class).to(Key.get(String.class, Names.named("config.db4o.database")));
In other words: you're not binding a constant value, as you're trying to bind to another key.
Hi guys,Quick question from a newbie using Guice.. :)I have the following module that I am using to persist my objects with db4o:
public class PersistenceModule extends AbstractModule {
private static final Logger logger = LoggerFactory.getLogger(DefaultBootstrapModule.class);private static final String BOOKINGS_DATA = "./target/bookings.data";
@Overrideprotected void configure() {install(PersistenceService.usingDb4o().across(UnitOfWork.TRANSACTION).buildModule());bindConstant().annotatedWith(Db4Objects.class).to(BOOKINGS_DATA);}}
Is there any way to "provide" to this module the database name, for example injecting the value into the module? What is the correct approach/pattern for this case?The idea is to take this configuration parameter from a properties file. I have already an object that provides me these values from the property, but i cant find the way to inject it to this module. I dont know if its possible but i assume that is a pretty common use case, so i would like to know what is the best way to do it.Thanks!
--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.