Hi Lachlan,

Indeed, that is a much simpler and straight to the point solution. :)

Cheers,

Henrique

On 11/04/2012, at 15:55, Lachlan Deck wrote:

> On 11/04/2012, at 12:28 PM, Ramsey Gurley wrote:
> 
>> What if I want an advanced service on component one and a basic service on 
>> component two?
> 
> class ComponentOne
> {
>       @Inject
>       AdvancedService service;
> }
> class ComponentTwo
> {
>       @Inject
>       BasicService service;
> }
> 
> <...>
> class AppModule
> {
>       void configure()
>       {
>               bind(BasicService.class).to(BasicServiceImpl.class);
>               bind(AdvancedService.class).to(AdvancedServiceImpl.class);
>       }
> }
> 
> Next you'll ask, what if I have two types of advanced services and depending 
> on certain conditions I want one or the other (e.g., session-aware or not). 
> It's quite flexible and can be nicely done. Refer to guice docs.
> 
> e.g.,
> bind(ConditionalService.class).toProvider(ConditionalServiceProvider.class);
> 
> class ConditionalServiceProvider implements Provider<ConditionalService>
> {
>       @Inject @Current
>       WOContext context;
> 
>       public ConditionalService get()
>       {
>               <...>
>       }
> }
> 
> The other thing to say about IoC is that it serves another purpose, that of 
> allowing for easy mocking in unit tests, and testing that 'thing' separately.
> 
> cheers,
> Lachlan Deck
> 


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to