Re: [ANN] WOInject 1.0
Re: [ANN] WOInject 1.0
- Subject: Re: [ANN] WOInject 1.0
- From: Ramsey Gurley <email@hidden>
- Date: Tue, 10 Apr 2012 19:28:15 -0700
On Apr 7, 2012, at 8:07 PM, Henrique Prange wrote:
> Suppose you have a Service interface and a BasicService implementation for it. This Service is required across your components. So you have something like this:
>
> class ComponentOne {
> Service service = new BasicService();
> }
>
> class ComponentTwo {
> Service service = new BasicService();
> }
>
> ...
>
> Then, the project evolves, and you develop a new AdvancedService implementation for the Service interface. You have to traverse the entire code base updating the instantiation of Service.
>
> On the other hand, if you use Guice, you can delegate the creation of Services to Guice, and inject the instances of Service when required. You write code like this:
>
> class ComponentOne {
> @Inject
> Service service;
> }
>
> class ComponentTwo {
> @Inject
> Service service;
> }
>
> ...
>
> And you configure a Guice Module to specify that you want an instance of BasicService (or an AdvancedService) when you need a Service.
>
> class AppModule extends AbstractModule {
> void configure() {
> bind(Service.class).to(BasicService.class);
> }
> }
>
> If you need to change the implementation class, you just have to redefine your module:
>
> class AppModule extends AbstractModule {
> void configure() {
> bind(Service.class).to(AdvancedService.class);
> }
> }
>
What if I want an advanced service on component one and a basic service on component two?
Ramsey
_______________________________________________
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