I think the missing ingredient we need to prescribe the appropriate solution
is knowledge of how you know the current Season?  Is it a value that is
scoped?  Is it a value that is passed as a method arg, and can vary
regardless of scope?

On Tue, Feb 1, 2011 at 12:46 PM, Colin Decker <[email protected]> wrote:

> Another option:
>
> class SeasonalPromoProvider implements Provider<Promo> {
>   @Inject Provider<Season> seasonProvider;
>   @Inject Map<Season, Provider<Promo>> seasonalPromoMap; // bind with
> MapBinder
>
>   public Promo get() {
>     return seasonalPromoMap.get(seasonProvider.get()).get(); // enough gets
> for one line?
>   }
> }
>
> Colin
>
>
>
> On Tue, Feb 1, 2011 at 12:18 PM, Philippe Beaudoin <
> [email protected]> wrote:
>
>> I have been using factories to do this. Something like:
>>
>>
>> class PromoFactory {
>>  @Inject
>>  Provider<SpringPromo> springPromo;
>>
>>  @Inject
>>  Provider<WinterPromo> winterPromo;
>>
>>  Promo getPromo(Season season) {
>>    if( season == Season.Winter ) return winterPromo;
>>    return springPromo;
>>  }
>> }
>>
>> Then inject the PromoFactory.
>>
>> This pattern can be used for the various other scenarios you describe,
>> I believe.
>>
>>   Philippe
>>
>> On Tue, Feb 1, 2011 at 2:24 AM, Adrian <[email protected]> wrote:
>> > Hello,
>> >
>> > I have the following problem :
>> >
>> > Let's say that I have a Display class which needs a Promo to display.
>> >
>> > I have two type of promos SpringPromo and WinterPromo.
>> >
>> > The display doesn't care what kind of promo it displays as long it is
>> > a Promo.
>> >
>> > I would like to find a solution so
>> > - when season is Winter, to inject WinterPromo
>> > - when seazon is Spring, to inject SpringPromo
>> >
>> > Can you help me find a solution ?
>> >
>> > What if there are other (many)kinds of promos which depend on
>> > seasons ?
>> > What if there are other (many)kinds of seasons ?
>> > What if not only Promos depend on seazon ?
>> >
>> > Thank you,
>> >
>> > Adrian
>> >
>> > --
>> > 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]<google-guice%[email protected]>
>> .
>> > For more options, visit this group at
>> http://groups.google.com/group/google-guice?hl=en.
>> >
>> >
>>
>> --
>> 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]<google-guice%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/google-guice?hl=en.
>>
>>
>  --
> 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]<google-guice%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>

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