How do I write a Guice Provider that doesn't explicitly create objects?

Posted by ripper234 on Stack Overflow See other posts from Stack Overflow or by ripper234
Published on 2010-04-15T16:28:02Z Indexed on 2010/04/15 16:33 UTC
Read the original article Hit count: 128

Filed under:
|
|

Say I have a ClassWithManyDependencies. I want to write a Guice Provider for this class, in order to create a fresh instance of the class several times in my program (another class will depend on this Provider and use it at several points to create new instances).

One way to achieve this is by having the Provider depend on all the dependencies of ClassWithManyDependencies. This is quite ugly.

Is there a better way to achieve this?

Note - I certainly don't want the Provider to depend on the injector. Another option I considered is having ClassWithManyDependencies and ClassWithManyDependenciesProvider extend the same base class, but it's butt ugly.

© Stack Overflow or respective owner

Related posts about java

Related posts about guice