zhao yi escribió:
> I didn't see there is any different between guice and factory pattern.
> Is there a full example for using this?

I've used @Assisted and the builder pattern to get something that looks like 
your needs.

In the Module:

     binder.bind(ISignerFactory.class)
           .toProvider(FactoryProvider.newFactory(ISignerFactory.class, 
    SignerHelper.class));

In SignerHelper:

     @Inject @RawSigner ISigner rawSigner;
     @Inject @CMSSigner ISigner cmsSigner;

     @Inject
     public SignerHelper(@Assisted String selectedSigner) {
         this.signer = selectedSigner;
     }


     public ISigner build() {
        if (this.signer.equalsIgnoreCase("raw")) {
           return rawSigner;
         } else if ...
     }

And using it like this:

     private final ISignerFactory signerFactory;

     @Inject
     TestSigner(ISignerFactory signerFactory) {
         this.signerFactory = signerfactory;
     }

     public void sign() {
         ISigner signer = this.signerFactory.create(selectedSigner).build();
     }

I don't know if this is the most correct way to accomplish it, but it works.

Bye     

--~--~---------~--~----~------------~-------~--~----~
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