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 protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]