Passing dynmic parameters to a third party library constructor

46 views
Skip to first unread message

Joseph

unread,
Nov 23, 2014, 2:49:27 PM11/23/14
to google...@googlegroups.com
Hello,

I need to make multiple objects of a client that takes a config object as a parameter. So for example, to do this using "new" I would do:

Config conf = new Conf(123, 444, "whatever");


Client client = new Client(conf);

I realize I can have a Provides method for Config and a Provides method for Client, that has Config injected, however, Config's parameters are not constant and not passed in the command line or a config file. They are constantly changing and from a db, and the row in the db is not constant, as I am making multiple objects. Config and Client are from third party libraries so I cannot add @Assisted to their constructors.


Fred Faber

unread,
Nov 23, 2014, 7:03:46 PM11/23/14
to google...@googlegroups.com
At some point you want to consider that wrapping db-reads in a Provider method is hiding too much logic in an abstraction. Stay thin if you can.

What would you gain with the injection?

--
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/c3b1aab1-3ea0-45c7-a01e-71560766392b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joseph

unread,
Nov 25, 2014, 5:55:22 PM11/25/14
to google...@googlegroups.com, ffa...@faiser.com
Hi Freb,

I would prefer not to read from the db in a Provider method. I am trying to figure out how to inject an object that needs another object, that needs dynamic parameters so that I can avoid using "new".


Thanks,
Joseph
Reply all
Reply to author
Forward
0 new messages