felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clement Escoffier <clement.escoff...@gmail.com>
Subject Re: Making sense of service binding and dependencies
Date Wed, 04 Feb 2009 11:08:32 GMT

On 04.02.2009, at 11:36, Marcel Offermans wrote:

> 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.

One of the cool aspect of iPOJO is that you can use either annotations  
(http://felix.apache.org/site/how-to-use-ipojo-annotations.html, http://felix.apache.org/site/presentations.data/ipojo-berlin-20080611.pdf)

, or XML (http://felix.apache.org/site/ipojo-in-10-minutes.html), or a  
fluent API.


Clement




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


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


Mime
View raw message