not sure I understand, but
On Jun 20, 2009, at 11:00, Karthik Krishnan 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.
or have PostMethod's GOOGLE_ACCOUNT_API_URL injected as well, then you
can drop the provider:
class PostMethod {
@Inject public PostMethod(@Named("GoogleAccountApiUrl") String
url) {...}
//...
}
bindConstant
().annotatedWith(Names.named("GoogleAccountApiUrl")).to("http://")
see
http://stubbisms.wordpress.com/2008/07/26/google-guice-injecting-primitives-in-constructors/
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---