jclouds is a major consumer of guice 2.0 functionality.  We pretty much use
it for everything.  Without guice jclouds would be a lot more complex.  We
love guice with its warts.

There is one wart hard to love: issue
146<http://code.google.com/p/google-guice/issues/detail?id=346>.
When reviewing our code with new recruits, I often wince at explaining this
one.  Currently AssistedInject is awesome for simple cases.  However,
needing to create a separate factory per object is most certainly
accidentaly complexity.  We end up copying and pasting code into factories
to get this to work.  I've pasted an example below of what that looks
like.

I understand a patch is written, but not scheduled for any release.   This
implies that this will haunt us for some time.  Unless this can make guice
2.1, I'd really like a second (third, ...) opinion on how to work around
this.  I'm looking for a way to achieve multi-type assisted inject in some
way that doesn't involve copy/pasting boilerplates or needing to compile our
own vesion of guice.

I'd like people to have a pleasant experience with guice/jclouds when they
decide to contribute.   Any help greatly appreciated!

Cheers,
-Adrian
jclouds <http://code.google.com/p/jclouds/>


/**
 * temporary factory until guice can do multi-type assisted inject
 *
 * @see <a href="http://code.google.com/p/google-guice/issues/detail?id=346";
/>
 *
 * @author Adrian Cole
 */
public class CommandFactory {

   @Inject
   private ParseSaxFactory parseSaxFactory;

   public static interface ParseSaxFactory {
      ParseSax<?> create(ParseSax.HandlerWithResult<?> handler);
   }

   @Inject
   private GetAndParseSaxFactory getAndParseSaxFactory;

   public static interface GetAndParseSaxFactory {
      GetAndParseSax<?> create(String uri, ParseSax<?> callable);
   }

   public GetAndParseSax<?> createGetAndParseSax(String uri,
ParseSax.HandlerWithResult<?> handler) {
      return getAndParseSaxFactory.create(uri,
parseSaxFactory.create(handler));
   }

   @Inject
   private GetStringFactory getStringFactory;

   public static interface GetStringFactory {
      GetString create(String uri);
   }

   public GetString createGetString(String uri) {
      return getStringFactory.create(uri);
   }

   @Inject
   private PutFactory putFactory;

   public static interface PutFactory {
      Put create(@Assisted("uri") String uri, @Assisted("payload") String
payload);
   }

   public Put createPut(String uri, String payload) {
      return putFactory.create(uri, payload);
   }

   @Inject
   private HeadFactory headFactory;

   public static interface HeadFactory {
      Head create(String uri);
   }

   public Head createHead(String uri) {
      return headFactory.create(uri);
   }

}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to