In case you really need to inject value classes, Guice does that for you for free. If you @Inject a Person (non-scoped), every time will give a new Person.
But I can't figure out why a simple value class should be managed by Guice. In this case I'm sure that's easier and clearer to just use a regular, old-fashioned new. If what you're looking for is to inject a Service in conjunction with some value class, take a look at Assisted Inject [1] hth, jordi [1] http://code.google.com/p/google-guice/wiki/AssistedInject On Thu, May 10, 2012 at 10:45 PM, Bubba 42 <bubba424...@gmail.com> wrote: > Hi, > > I've been unable to find a suitable answer to this question. > > If I understand this correctly: Dependency Injection can be used to > instantiate service objects -- object that essentially abstract away > some computational service ... for example (an instance of this class > would essentially be stateless, save for resources that it might be > plugged into such as SimpleMath.properties, and I would expect that > there would be small number of instances of this class per application > instance say under 5): > > class SimpleMath { > > public int addTwoNumbers (int n1, int n2) { > return n1 + n2; > } > > public int multiplyTwoNumbers (int n1, int n2) { > return n1 * n2; > } > > } > > Now can DI be used to instantiate value objects (for the lack of a > better word). By a value object I mean an object that has state and > the methods are impacted by that state, for example (as opposed to the > previous class I would expect there to be hundreds or thousands of > instances of this class): > > class Person { > > int age; > int weight; > String fname; > String lname; > // and so on > > public String hail() { > return "Hello to you to, I am " + fname + " " + lname; > } > > public String howOldAreYou() { > return "I don't really like talking about my age but I'm " + age + > " years young"; > } > > // and so on > > } > > Thanks. > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To post to this group, send email to google-guice@googlegroups.com. > To unsubscribe from this group, send email to > google-guice+unsubscr...@googlegroups.com. > 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 google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.