Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Injecting primitives and/or bind toInstance
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
astubbs  
View profile  
 More options Jul 25 2008, 9:20 am
From: astubbs <antony.stu...@gmail.com>
Date: Fri, 25 Jul 2008 06:20:59 -0700 (PDT)
Local: Fri, Jul 25 2008 9:20 am
Subject: Injecting primitives and/or bind toInstance
I created a blog post about injecting primitives and/or bind
toInstance because I didn't pick it up straight away off the user
guide and had to google it out a bit.for a clearer example. Just
wanted to share the love! Couldn't find anyone asking questions about
it in the forum either, so must be just me!
http://stubbisms.wordpress.com/2008/07/26/google-guice-injecting-prim...

Main problem was that I was reading the user guide too fast I think!


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dhanji R. Prasanna  
View profile  
 More options Jul 25 2008, 7:52 pm
From: "Dhanji R. Prasanna" <dha...@gmail.com>
Date: Sat, 26 Jul 2008 09:52:21 +1000
Local: Fri, Jul 25 2008 7:52 pm
Subject: Re: Injecting primitives and/or bind toInstance

Interesting.

You don't have to use the named annotation, you can use any binding
annotation. Plus one minor advantage strings in @Named have over bean-ids in
Spring is that you can point to a string constant checked at compile time:
bindConstant().annotatedWith(named(AN_INT)).to(12);

//elsewhere..
@Inject @Named(AN_INT) int x;

Dhanji.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
astubbs  
View profile  
 More options Jul 25 2008, 8:50 pm
From: astubbs <antony.stu...@gmail.com>
Date: Fri, 25 Jul 2008 17:50:40 -0700 (PDT)
Local: Fri, Jul 25 2008 8:50 pm
Subject: Re: Injecting primitives and/or bind toInstance
Ah yes I think I gathered that but I was hell bent on not having to
actually create my own annotation just to inject a string into my
constructor args. Is that actually what you are refering to?

So AN_INT - is that an annotation you'd have to create? It would
really help my understanding if you could complete the example you
posted?

On Jul 26, 11:52 am, "Dhanji R. Prasanna" <dha...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dhanji R. Prasanna  
View profile  
 More options Jul 26 2008, 3:06 am
From: "Dhanji R. Prasanna" <dha...@gmail.com>
Date: Sat, 26 Jul 2008 17:06:21 +1000
Local: Sat, Jul 26 2008 3:06 am
Subject: Re: Injecting primitives and/or bind toInstance

On Sat, Jul 26, 2008 at 10:50 AM, astubbs <antony.stu...@gmail.com> wrote:

> Ah yes I think I gathered that but I was hell bent on not having to
> actually create my own annotation just to inject a string into my
> constructor args. Is that actually what you are refering to?

> So AN_INT - is that an annotation you'd have to create? It would
> really help my understanding if you could complete the example you
> posted?

//module class:
public static final String AN_INT = "anInt";

...configure() {
     bindConstant().annotatedWith(named(AN_INT)).to(12);

}

//elsewhere:
@Inject @Named(MyModule.AN_INT) int x;

Dhanji.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
astubbs  
View profile  
 More options Jul 26 2008, 3:22 am
From: astubbs <antony.stu...@gmail.com>
Date: Sat, 26 Jul 2008 00:22:11 -0700 (PDT)
Local: Sat, Jul 26 2008 3:22 am
Subject: Re: Injecting primitives and/or bind toInstance
Ah yes of course, I see what you were saying now...

In other news...

I've updated my blog with some examples that I was inspired from
reading a post on Dhanji R. Prasanna's blog:
http://stubbisms.wordpress.com/2008/07/26/google-guice-injecting-prim...

My now favourite module binding for my use case is:
<pre>
      String DEFAULT_PET_NAME = "suki";

      bind(HouseHoldPet.class).toProvider(new Provider<HouseHoldPet>()
      {
         public HouseHoldPet get()
         {
            return new HouseHoldPet(DEFAULT_PET_NAME);
         }
      });
</pre>

On Jul 26, 7:06 pm, "Dhanji R. Prasanna" <dha...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google