Re: [ANN] WOInject 1.0
Re: [ANN] WOInject 1.0
- Subject: Re: [ANN] WOInject 1.0
- From: Lachlan Deck <email@hidden>
- Date: Thu, 12 Apr 2012 04:55:33 +1000
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 (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden