felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcel Offermans <marcel.offerm...@luminis.nl>
Subject Re: Making sense of service binding and dependencies
Date Wed, 04 Feb 2009 10:36:17 GMT
On Feb 4, 2009, at 11:16 , Clement Escoffier wrote:

>> DependencyManager and iPOJO definitely can help too. The benefit of
>> these types of dependency injection tools is that they actually
>> manage the life cycle of your component, so it won't even be created
>> until your dependencies are satisfied. Check out my iPOJO
>> presentation under the presentations section of the documentation
>> page on the Felix web site for a simple example at the beginning of
>> the presentation for how you provide and require services in iPOJO,
>> as an example.
>
> Here is a simple example of how to implement it with iPOJO:
>
> @Component
> @Provides
> public class FooServiceImpl implements FooService {
>     @Requires
>     private BarService myBar;
>
>     public void doSomething() {
>        myBar.doSomethingWithBar();
>     }
> }
>
> That's simple, isn't it ?  You don't have to worry about BarService
> availability, iPOJO will manage this for you :-)

And the same thing in the DependencyManager:

public class FooServiceImpl implements FooService {
     private volatile BarService myBar;

     public void doSomething() {
         myBar.doSomethingWithBar();
     }
}

public class Activator extends DependencyActivatorBase {
     public void init(BundleContext c, DependencyManager m) {
         m.add(createService()
             .setInterface(FooService.class.getName(), null)
             .setImplementation(FooServiceImpl.class)
             .add
(createServiceDependency().setClass(BarService.class).setRequired(true))
         );
     }
}

Here you need no annotations at all in your POJO, all OSGi specific  
code is in the Activator, and you can define your services and their  
dependencies using a fluent API.

Greetings, Marcel


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Mime
View raw message