Sorry Pressed send too soon.
@Adrian: I think that is a good idea. That way I can bind different uris to
my post method.

Thanks,

Kartik

On Fri, Jul 24, 2009 at 2:06 PM, Karthik Krishnan
<[email protected]>wrote:

> @Jelle: I need to inject PostMethod mapped to a particular uri. For the
> moment:
>
>
> On Fri, Jul 24, 2009 at 1:13 AM, Adrian Cole <[email protected]> wrote:
>
>>
>> Hi, Karthik.
>>
>> I'd recommend separating the two bits in your provider, and using a
>> binding annotation.  Otherwise, guice will assume every time you want
>> a post method you want the google account one.  This could be
>> confusing later.
>>
>> Ex.
>>
>>
>>  
>> bindConstant().annotatedWith(GoogleAccount.class).toInstance(GOOGLE_ACCOUNT_API_URL);
>>
>>
>>  @Provides
>>  @GoogleAccount
>>  PostMethod provideGoogleAccountLoginPostMethod(@GoogleAccount String
>> googleAccountURI) {
>>    PostMethod postMethod
>>        = new PostMethod(googleAccountURI);
>>    return postMethod;
>>  }
>>
>>  @Inject
>>  public LoginServiceBroker(HttpClient httpClient, @GoogleAccount
>> PostMethod postMethod)  {
>>
>>
>> I hope this helps.
>> -Adrian
>> jclouds
>>
>>
>>
>> On Sat, Jun 20, 2009 at 11:00 AM, Karthik
>> Krishnan<[email protected]> wrote:
>> > Hi,
>> >
>> > I am playing around with Google Guice 2.0 after getting my hands wet
>> with
>> > Guice 1.x. I would like to add Guice gurus their opinion on what would
>> be
>> > most appropriate. My use case : I am trying to authenticate using
>> Google's
>> > authentication api which requires a post request to a ClientLogin url
>> with
>> > appropriate request params. My code
>> >
>> > public GoogleLoginServiceBroker implements ILoginServiceBroker {
>> >
>> > private final HttpClient httpClient;
>> >
>> > private final PostMethod postMethod;
>> >
>> > @Inject
>> > public LoginServiceBroker(HttpClient httpClient, PostMethod postMethod)
>> {
>> >   this.httpClient = httpClient;
>> >   this.postMethod = postMethod;
>> > }
>> >
>> > ..... methods to authenticate.
>> >
>> >
>> > }
>> >
>> >
>> > My module code
>> >
>> > /** Binds {...@link ILoginServiceBroker} to its implementation. */
>> >   @Override
>> >   protected void configure() {
>> >     bind(ILoginServiceBroker.class)
>> >         .to(LoginServiceBrokerImpl.class);
>> >   }
>> >
>> >   /**
>> >    * Injects an instance of {...@link PostMethod} for Google's <em>Client
>> > Interface</em>.
>> >    */
>> >   @Provides
>> >   PostMethod provideGoogleAccountLoginPostMethod() {
>> >     PostMethod postMethod
>> >         = new PostMethod(GOOGLE_ACCOUNT_API_URL);
>> >     return postMethod;
>> >   }
>> >
>> > My question to Guice gurus is this:
>> >
>> > Is this approach correct Should an ordinary binding suffice in this
>> > scenario? Since I have to configure  PostMethod to point to a specific
>> url,
>> > I am using @Provides annotation for that purpose. I just need AN
>> instance of
>> > HttpClient so I have not bound to any instance. Guice manages to inject
>> the
>> > dependency anyway.
>> >
>> > Any advice/opinion/feedback would be extremely helpful.
>> >
>> > Thanks,
>> >
>> > Karthik Krishnan
>> >
>> > >
>> >
>>
>> >>
>>
>

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