You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Miroslav Nachev <m....@prosyst.bg> on 2008/10/14 08:42:36 UTC

Dependency Injection with annotations

Hi,

I would like to ask you about some way in Felix to export services in 
more easy way only with annotation like in EJB3.x: @Stateful, 
@Stateless, @Remote, @Local, @EJB, etc.
In my opinion the best way this to be done is inside of the OSGi 
framework. Then all resources (services) can be exported to the 
framework just with annotation. The same for needed services. What about 
if before to get some service we have to pass some parameters to the 
constructor?


Regards,
Miro.

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


Re: Dependency Injection with annotations

Posted by Stuart McCulloch <mc...@gmail.com>.
2008/10/17 Miroslav Nachev <m....@prosyst.bg>

> Hello Stuart,
>
> I am little bit familiar with Guice and Peaberry and I can say that I am
> not happy to them. If you are familiar with Java EE I would like to compare
> Guice and Peaberry with EJB 2.x and Java EE 1.4 where most of
> routine/repeated works was done from the programmer and the popularity of
> EJB 2.x was not so good. Now with EJB 3 the things are changed because if
> you don't want to use some specific configurations you use only few
> annotations to create EJB 3.x from POJO bean: @Remote, @Local, @Stateful,
> @Stateless. Unfortunately this is not the case with Guice and Peaberry. In
> my opinion this improvement can be done only if the dependency injection is
> part of OSGi Framework implementation and it will be much better if this is
> a part of the OSGi Specification.
>

Well I strongly disagree that this can *only* be done by making DI part of
the OSGi framework!
The success of OSGi has (in part) come from the fact that other frameworks
and containers can
build on top of the core without bloating it - that's why there's a service
registry in the first place.

As seen with Spring-DM, iPOJO, etc. it is possible to build a component
model on top of OSGi
without pushing dependency injection down into the core - and as a
counterpoint, what-if EJB3
dependency injection was part of the core and a new approach came out? We'd
be left with a
load of code that people didn't want to use anymore (especially in the
embedded space).

Thankfully there are a number of upcoming developments which could help with
your use-case,
such as the registry hooks - and enhancements to Guice, like possible
support for WebBeans:


http://groups.google.com/group/google-guice/browse_thread/thread/cc5a03872cea6487

If this falls the right way then it would be possible to use
Guice+peaberry+OSGi like you say.

PS. as Richard said, in your last example it's very doubtful that any
approach would be able
to automatically inject an object that's been 'new'd (at least without JVM
support) - you would
need another step, like Guice's injectMembers method.

Regards,
> Miro.


-- 
Cheers, Stuart

Re: Dependency Injection with annotations

Posted by Miroslav Nachev <m....@prosyst.bg>.
Hello Stuart,

I am little bit familiar with Guice and Peaberry and I can say that I am 
not happy to them. If you are familiar with Java EE I would like to 
compare Guice and Peaberry with EJB 2.x and Java EE 1.4 where most of 
routine/repeated works was done from the programmer and the popularity 
of EJB 2.x was not so good. Now with EJB 3 the things are changed 
because if you don't want to use some specific configurations you use 
only few annotations to create EJB 3.x from POJO bean: @Remote, @Local, 
@Stateful, @Stateless. Unfortunately this is not the case with Guice and 
Peaberry. In my opinion this improvement can be done only if the 
dependency injection is part of OSGi Framework implementation and it 
will be much better if this is a part of the OSGi Specification.


Regards,
Miro.


Stuart McCulloch wrote:
> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>
>   
>> Hi,
>>
>> This is very interesting and I will try it but this answer is half of my
>> question. I am interesting how to get some service in my code, not in
>> another service. For example:
>>
>> public class SomePOJOBean
>> {
>>
>>   @Requires
>>   ??? how to pass some parameters to the service (passive, dynamics)
>>   private FooService foo;
>>
>> }
>>
>> How can be implemented the above scenario?
>>
>>     
>
> Well, iPOJO injects components - but these are not necessarily services.
>
> Clement's example happened to provide a service, but this isn't mandatory.
> You do need to tell iPOJO about your code somehow, and in iPOJO this is done
> by marking them as components which iPOJO injects as necessary. (I'm sure
> Clement can explain this better than me!)
>
> There are also alternative ways to inject OSGi services, using (non-OSGi)
> dependency injection frameworks:
>
>  * Spring has the Spring-DM extension, but I don't know if it fully supports
> configuration via annotation.
>
>    http://www.springframework.org/osgi/
>
>  * Guice has the peaberry extension, which I work on - in this case the
> service configuration is done in the binding module, not the annotation (I
> did look at doing annotation configuration, but this rapidly becomes a
> management nightmare)
>
>    http://code.google.com/p/peaberry/
>
> HTH
>
> Regards,
>   
>> Miro.
>>
>>
>>
>> clement escoffier wrote:
>>
>>     
>>> Hi,
>>>
>>> iPOJO provides such annotations as:
>>> @Component
>>> @Provides // Provides a service
>>> public class Foo implements Service {
>>>    @Requires // Service dependency
>>>    private HelloService hello;
>>>
>>>
>>>    ...
>>> }
>>>
>>> You can find further info at
>>> http://felix.apache.org/site/how-to-use-ipojo-annotations.html
>>>
>>> About parameters, the iPOJO's way is to inject instance property. Those
>>> fields will be set before the execution of your constructor (between the
>>> super constructor invocation and the constructor code), and your
>>> constructor
>>> can use those fields, such as in:
>>>
>>> @Component
>>> @Provides // Provides a service
>>> public class Foo implements Service {
>>>
>>>    @Property
>>>    private String myString;
>>>
>>>    @Requires // Service dependency
>>>    private HelloService hello;
>>>
>>>    public Foo() {
>>>      // Can use myString here as well as hello
>>>    }
>>>    ...
>>> }
>>>
>>> Regards,
>>>
>>> Clement
>>>
>>>
>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>
>>>
>>>
>>>       
>>>> Hi,
>>>>
>>>> I would like to ask you about some way in Felix to export services in
>>>> more
>>>> easy way only with annotation like in EJB3.x: @Stateful, @Stateless,
>>>> @Remote, @Local, @EJB, etc.
>>>> In my opinion the best way this to be done is inside of the OSGi
>>>> framework.
>>>> Then all resources (services) can be exported to the framework just with
>>>> annotation. The same for needed services. What about if before to get
>>>> some
>>>> service we have to pass some parameters to the constructor?
>>>>
>>>>
>>>> Regards,
>>>> Miro.
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>
>>
>>     
>
>
>   


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


Re: Dependency Injection with annotations

Posted by "Richard S. Hall" <he...@ungoverned.org>.
Miroslav Nachev wrote:
> Hi,
>
> I have some way to solve that problem. My question was for some 
> standardized way which to be common practice.
> My scenario is when I have one bundle it is not possible everything to 
> be in the Activator and Service(s) implementation. In most of the 
> cases we need of some helper classes which needs to use another 
> services from another bundles. This is the problem that I would like 
> to solve in simple way, not so difficulty how is solved with Guice & 
> Peaberry. Guice & Peaberry solve that problem but when we have a chain 
> of services and classes it is very hard to do initial initialization. 
> In the same way this can be done very simple if they are part of the 
> OSGi Framework implementation.

So, let me see if I understand. You want a way to have internal class 
instances (i.e., instances that are not components managed by iPOJO) to 
be injected with services. Is that correct?

-> richard

>
>
> Miro.
>
>
> Richard S. Hall wrote:
>> Miroslav Nachev wrote:
>>> Hello Clement,
>>>
>>> In traditional way if I have some OSGi Service which have to be used 
>>> in some class (POJO Bean) I MUST pass this service to one or more 
>>> classes as parameter. Then when the time for using of that service 
>>> is on the service can be unavailable. Similar problem I will have 
>>> when I want to stop my bundle. That's why if iPOJO Annotations allow 
>>> some service to be used inside of the bundle will be perfect. This 
>>> can be done with Proxy. When I create some new object with new 
>>> JavaClass(...) and in that object I am declared some OSGi Service 
>>> using iPOJO Annotation, that service will point to some Proxy which 
>>> proxy will try to get the service on request. This will guarantee 
>>> that the service is actual independently how much the service is 
>>> restarted and updated. In traditional way the application must track 
>>> all service states and etc. Passing the service as parameter 
>>> complicate the things.
>>>
>>> Did you have some plans iPOJO to support the above scenario?
>>
>> I am not totally sure I understand your scenario, but it sounds like 
>> you want a proxy that only tries to get the service when someone 
>> tries to use it. iPOJO does not support this type of scenario 
>> automatically, but it is fairly easy to achieve. Assume you have the 
>> following service:
>>
>>    public interface Foo {
>>        void doFoo();
>>    }
>>
>> You could create a component like this:
>>
>>    import org.apache.felix.ipojo.temporal.Requires;
>>
>>    public class MyFooProxy implements Foo {
>>        @Requires
>>        private Foo m_foo;
>>
>>        public void doFoo() {
>>            m_foo.doFoo();
>>        }
>>    }
>>
>> The dependency on m_foo is declared to be temporal, which means that 
>> it will only try to get the service when it is used. If one is not 
>> available, it will eventually timeout and throw an exception. Now you 
>> should be able to pass this "proxy" component to you components and 
>> they will be able to use the service on demand.
>>
>> -> richard
>>
>>>
>>>
>>> Regards,
>>> Miro.
>>>
>>>
>>> clement escoffier wrote:
>>>> 2008/10/14 Stuart McCulloch <mc...@gmail.com>
>>>>
>>>>  
>>>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>>>
>>>>>  
>>>>>> Hi,
>>>>>>
>>>>>> This is very interesting and I will try it but this answer is 
>>>>>> half of my
>>>>>> question. I am interesting how to get some service in my code, 
>>>>>> not in
>>>>>> another service. For example:
>>>>>>
>>>>>> public class SomePOJOBean
>>>>>> {
>>>>>>
>>>>>>   @Requires
>>>>>>   ??? how to pass some parameters to the service (passive, dynamics)
>>>>>>   private FooService foo;
>>>>>>
>>>>>> }
>>>>>>
>>>>>> How can be implemented the above scenario?
>>>>>>       
>>>>
>>>> So, as I understand, you don't want (global) services but your own
>>>> (customized) service. As you're configuring the service, this 
>>>> service should
>>>> not be available to other consumers. In iPOJO you can do this by using
>>>> composites (the new documentation is coming soon). Composites 
>>>> assert that
>>>> your service is isolated. However, composites does not allows you 
>>>> to declare
>>>> those services in your code.
>>>>
>>>>
>>>>  
>>>>> Well, iPOJO injects components - but these are not necessarily 
>>>>> services.
>>>>>
>>>>> Clement's example happened to provide a service, but this isn't 
>>>>> mandatory.
>>>>> You do need to tell iPOJO about your code somehow, and in iPOJO 
>>>>> this is
>>>>> done
>>>>> by marking them as components which iPOJO injects as necessary. 
>>>>> (I'm sure
>>>>> Clement can explain this better than me!)
>>>>>     
>>>>
>>>>
>>>> Service providing is (of course) not necessary. Your component can 
>>>> be a
>>>> component that does not provide a service (like a GUI).
>>>>
>>>>
>>>> Clement
>>>>
>>>>
>>>>  
>>>>> There are also alternative ways to inject OSGi services, using 
>>>>> (non-OSGi)
>>>>> dependency injection frameworks:
>>>>>
>>>>>  * Spring has the Spring-DM extension, but I don't know if it fully
>>>>> supports
>>>>> configuration via annotation.
>>>>>
>>>>>   http://www.springframework.org/osgi/
>>>>>
>>>>>  * Guice has the peaberry extension, which I work on - in this 
>>>>> case the
>>>>> service configuration is done in the binding module, not the 
>>>>> annotation (I
>>>>> did look at doing annotation configuration, but this rapidly 
>>>>> becomes a
>>>>> management nightmare)
>>>>>
>>>>>   http://code.google.com/p/peaberry/
>>>>>
>>>>> HTH
>>>>>
>>>>> Regards,
>>>>>  
>>>>>> Miro.
>>>>>>
>>>>>>
>>>>>>
>>>>>> clement escoffier wrote:
>>>>>>
>>>>>>    
>>>>>>> Hi,
>>>>>>>
>>>>>>> iPOJO provides such annotations as:
>>>>>>> @Component
>>>>>>> @Provides // Provides a service
>>>>>>> public class Foo implements Service {
>>>>>>>    @Requires // Service dependency
>>>>>>>    private HelloService hello;
>>>>>>>
>>>>>>>
>>>>>>>    ...
>>>>>>> }
>>>>>>>
>>>>>>> You can find further info at
>>>>>>> http://felix.apache.org/site/how-to-use-ipojo-annotations.html
>>>>>>>
>>>>>>> About parameters, the iPOJO's way is to inject instance 
>>>>>>> property. Those
>>>>>>> fields will be set before the execution of your constructor 
>>>>>>> (between the
>>>>>>> super constructor invocation and the constructor code), and your
>>>>>>> constructor
>>>>>>> can use those fields, such as in:
>>>>>>>
>>>>>>> @Component
>>>>>>> @Provides // Provides a service
>>>>>>> public class Foo implements Service {
>>>>>>>
>>>>>>>    @Property
>>>>>>>    private String myString;
>>>>>>>
>>>>>>>    @Requires // Service dependency
>>>>>>>    private HelloService hello;
>>>>>>>
>>>>>>>    public Foo() {
>>>>>>>      // Can use myString here as well as hello
>>>>>>>    }
>>>>>>>    ...
>>>>>>> }
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> Clement
>>>>>>>
>>>>>>>
>>>>>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>      
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I would like to ask you about some way in Felix to export 
>>>>>>>> services in
>>>>>>>> more
>>>>>>>> easy way only with annotation like in EJB3.x: @Stateful, 
>>>>>>>> @Stateless,
>>>>>>>> @Remote, @Local, @EJB, etc.
>>>>>>>> In my opinion the best way this to be done is inside of the OSGi
>>>>>>>> framework.
>>>>>>>> Then all resources (services) can be exported to the framework 
>>>>>>>> just
>>>>>>>>           
>>>>> with
>>>>>  
>>>>>>>> annotation. The same for needed services. What about if before 
>>>>>>>> to get
>>>>>>>> some
>>>>>>>> service we have to pass some parameters to the constructor?
>>>>>>>>
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>> Miro.
>>>>>>>>
>>>>>>>> --------------------------------------------------------------------- 
>>>>>>>>
>>>>>>>> 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
>>>>>>
>>>>>>
>>>>>>       
>>>>> -- 
>>>>> Cheers, Stuart
>>>>>
>>>>>     
>>>>
>>>>   
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> 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


Re: Dependency Injection with annotations

Posted by Miroslav Nachev <m....@prosyst.bg>.
Hi,

I have some way to solve that problem. My question was for some 
standardized way which to be common practice.
My scenario is when I have one bundle it is not possible everything to 
be in the Activator and Service(s) implementation. In most of the cases 
we need of some helper classes which needs to use another services from 
another bundles. This is the problem that I would like to solve in 
simple way, not so difficulty how is solved with Guice & Peaberry. Guice 
& Peaberry solve that problem but when we have a chain of services and 
classes it is very hard to do initial initialization. In the same way 
this can be done very simple if they are part of the OSGi Framework 
implementation.


Miro.


Richard S. Hall wrote:
> Miroslav Nachev wrote:
>> Hello Clement,
>>
>> In traditional way if I have some OSGi Service which have to be used 
>> in some class (POJO Bean) I MUST pass this service to one or more 
>> classes as parameter. Then when the time for using of that service is 
>> on the service can be unavailable. Similar problem I will have when I 
>> want to stop my bundle. That's why if iPOJO Annotations allow some 
>> service to be used inside of the bundle will be perfect. This can be 
>> done with Proxy. When I create some new object with new 
>> JavaClass(...) and in that object I am declared some OSGi Service 
>> using iPOJO Annotation, that service will point to some Proxy which 
>> proxy will try to get the service on request. This will guarantee 
>> that the service is actual independently how much the service is 
>> restarted and updated. In traditional way the application must track 
>> all service states and etc. Passing the service as parameter 
>> complicate the things.
>>
>> Did you have some plans iPOJO to support the above scenario?
>
> I am not totally sure I understand your scenario, but it sounds like 
> you want a proxy that only tries to get the service when someone tries 
> to use it. iPOJO does not support this type of scenario automatically, 
> but it is fairly easy to achieve. Assume you have the following service:
>
>    public interface Foo {
>        void doFoo();
>    }
>
> You could create a component like this:
>
>    import org.apache.felix.ipojo.temporal.Requires;
>
>    public class MyFooProxy implements Foo {
>        @Requires
>        private Foo m_foo;
>
>        public void doFoo() {
>            m_foo.doFoo();
>        }
>    }
>
> The dependency on m_foo is declared to be temporal, which means that 
> it will only try to get the service when it is used. If one is not 
> available, it will eventually timeout and throw an exception. Now you 
> should be able to pass this "proxy" component to you components and 
> they will be able to use the service on demand.
>
> -> richard
>
>>
>>
>> Regards,
>> Miro.
>>
>>
>> clement escoffier wrote:
>>> 2008/10/14 Stuart McCulloch <mc...@gmail.com>
>>>
>>>  
>>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>>
>>>>   
>>>>> Hi,
>>>>>
>>>>> This is very interesting and I will try it but this answer is half 
>>>>> of my
>>>>> question. I am interesting how to get some service in my code, not in
>>>>> another service. For example:
>>>>>
>>>>> public class SomePOJOBean
>>>>> {
>>>>>
>>>>>   @Requires
>>>>>   ??? how to pass some parameters to the service (passive, dynamics)
>>>>>   private FooService foo;
>>>>>
>>>>> }
>>>>>
>>>>> How can be implemented the above scenario?
>>>>>       
>>>
>>> So, as I understand, you don't want (global) services but your own
>>> (customized) service. As you're configuring the service, this 
>>> service should
>>> not be available to other consumers. In iPOJO you can do this by using
>>> composites (the new documentation is coming soon). Composites assert 
>>> that
>>> your service is isolated. However, composites does not allows you to 
>>> declare
>>> those services in your code.
>>>
>>>
>>>  
>>>> Well, iPOJO injects components - but these are not necessarily 
>>>> services.
>>>>
>>>> Clement's example happened to provide a service, but this isn't 
>>>> mandatory.
>>>> You do need to tell iPOJO about your code somehow, and in iPOJO 
>>>> this is
>>>> done
>>>> by marking them as components which iPOJO injects as necessary. 
>>>> (I'm sure
>>>> Clement can explain this better than me!)
>>>>     
>>>
>>>
>>> Service providing is (of course) not necessary. Your component can be a
>>> component that does not provide a service (like a GUI).
>>>
>>>
>>> Clement
>>>
>>>
>>>  
>>>> There are also alternative ways to inject OSGi services, using 
>>>> (non-OSGi)
>>>> dependency injection frameworks:
>>>>
>>>>  * Spring has the Spring-DM extension, but I don't know if it fully
>>>> supports
>>>> configuration via annotation.
>>>>
>>>>   http://www.springframework.org/osgi/
>>>>
>>>>  * Guice has the peaberry extension, which I work on - in this case 
>>>> the
>>>> service configuration is done in the binding module, not the 
>>>> annotation (I
>>>> did look at doing annotation configuration, but this rapidly becomes a
>>>> management nightmare)
>>>>
>>>>   http://code.google.com/p/peaberry/
>>>>
>>>> HTH
>>>>
>>>> Regards,
>>>>   
>>>>> Miro.
>>>>>
>>>>>
>>>>>
>>>>> clement escoffier wrote:
>>>>>
>>>>>     
>>>>>> Hi,
>>>>>>
>>>>>> iPOJO provides such annotations as:
>>>>>> @Component
>>>>>> @Provides // Provides a service
>>>>>> public class Foo implements Service {
>>>>>>    @Requires // Service dependency
>>>>>>    private HelloService hello;
>>>>>>
>>>>>>
>>>>>>    ...
>>>>>> }
>>>>>>
>>>>>> You can find further info at
>>>>>> http://felix.apache.org/site/how-to-use-ipojo-annotations.html
>>>>>>
>>>>>> About parameters, the iPOJO's way is to inject instance property. 
>>>>>> Those
>>>>>> fields will be set before the execution of your constructor 
>>>>>> (between the
>>>>>> super constructor invocation and the constructor code), and your
>>>>>> constructor
>>>>>> can use those fields, such as in:
>>>>>>
>>>>>> @Component
>>>>>> @Provides // Provides a service
>>>>>> public class Foo implements Service {
>>>>>>
>>>>>>    @Property
>>>>>>    private String myString;
>>>>>>
>>>>>>    @Requires // Service dependency
>>>>>>    private HelloService hello;
>>>>>>
>>>>>>    public Foo() {
>>>>>>      // Can use myString here as well as hello
>>>>>>    }
>>>>>>    ...
>>>>>> }
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Clement
>>>>>>
>>>>>>
>>>>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>>>>
>>>>>>
>>>>>>
>>>>>>       
>>>>>>> Hi,
>>>>>>>
>>>>>>> I would like to ask you about some way in Felix to export 
>>>>>>> services in
>>>>>>> more
>>>>>>> easy way only with annotation like in EJB3.x: @Stateful, 
>>>>>>> @Stateless,
>>>>>>> @Remote, @Local, @EJB, etc.
>>>>>>> In my opinion the best way this to be done is inside of the OSGi
>>>>>>> framework.
>>>>>>> Then all resources (services) can be exported to the framework just
>>>>>>>           
>>>> with
>>>>   
>>>>>>> annotation. The same for needed services. What about if before 
>>>>>>> to get
>>>>>>> some
>>>>>>> service we have to pass some parameters to the constructor?
>>>>>>>
>>>>>>>
>>>>>>> Regards,
>>>>>>> Miro.
>>>>>>>
>>>>>>> --------------------------------------------------------------------- 
>>>>>>>
>>>>>>> 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
>>>>>
>>>>>
>>>>>       
>>>> -- 
>>>> Cheers, Stuart
>>>>
>>>>     
>>>
>>>   
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>
>


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


Re: Dependency Injection with annotations

Posted by "Richard S. Hall" <he...@ungoverned.org>.
Thinking about this more, I am just not sure if the use case is a good 
one or not.

It seems like you want something that manages your component's 
implementation details, but this doesn't really make sense. For a 
primitive component (i.e., one that is a Java class), it doesn't make 
sense that the container would know about and manage the implementation 
details, since those details are Java code.

The only way this makes sense is if the component is a composite 
component, i.e., the container is given a description of the internals 
of the component, then the container is responsible for everything 
inside of the component. This is how iPOJO composites work. You describe 
the composition of your component (i.e., its implementation) and then 
iPOJO is able to create and manage isolated instances of this composite 
component like any normal component.

-> richard


Richard S. Hall wrote:
> Miroslav Nachev wrote:
>> In "Hello Service Client using Annotations" project I am added the 
>> following class:
>> package ipojo.example;
>> import ipojo.example.hello.Hello;
>> import org.apache.felix.ipojo.annotations.Requires;
>> public class ExtraBean
>> {
>>    @Requires
>>    private Hello[] m_hello;
>>
>>    public ExtraBean()
>>    {
>>        System.out.println("ExtraBean.m_hello: " + m_hello);
>>    }
>>
>>    public String doWork()
>>    {
>>        return "Miro";
>>    }
>>
>> }
>>
>> Then I use that class in HelloClient.invokeHelloServices() as follow:
>>        ExtraBean extraBean = new ExtraBean();
>>        System.out.println("extraBean.doWork(): " + extraBean.doWork());
>
> iPOJO does not support this use case, since you want to create the 
> instance yourself. For iPOJO to manage the instance, it must create 
> it. You could perhaps get around this by using iPOJO factories to 
> create your instance:
>
>    http://felix.apache.org/site/how-to-use-ipojo-factories.html
>
>>
>> The error result when the bundle is started is:
>> ERROR: Error starting 
>> file:../hello.client.annotation/target/hello.client.annotation-0.8.0-SNAPSHOT.jar 
>> (org.osgi.framework.BundleException: Unresolved constraint in bundle 
>> 10: package; (package=ipojo.example))
>> org.osgi.framework.BundleException: Unresolved constraint in bundle 
>> 10: package; (package=ipojo.example)
>>        at 
>> org.apache.felix.framework.Felix._resolveBundle(Felix.java:1741)
>>        at org.apache.felix.framework.Felix._startBundle(Felix.java:1604)
>>        at org.apache.felix.framework.Felix.startBundle(Felix.java:1548)
>>        at 
>> org.apache.felix.framework.Felix.setFrameworkStartLevel(Felix.java:1142)
>>        at 
>> org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:265)
>>        at java.lang.Thread.run(Unknown Source)
>
> Perhaps your service object is not exporting this package? But the use 
> case is still not going to work.
>
> -> richard
>>
>>
>> Miro.
>>
>>
>> Clement Escoffier wrote:
>>> Hi,
>>> I will complete a little Richard's answer :-):
>>> The temporal dependency accepts several arguments:
>>> - timeout : setting the timeout time
>>> - onTimeout : defines the action to do when the timeout occurs.
>>>
>>> When requesting a temporal dependency, the thread is stopped until 
>>> the service appears or the timeout is reached (3s by default, set 
>>> the timeout to -1 to wait forever). When the timeout is reached, you 
>>> can define an action. By default a RuntimeException is thrown. But, 
>>> you can set the onTimeout action to do:
>>> - null: injects null
>>> - nullable: injects a fake service object that does nothing
>>> - empty-array: injects an empty array (only for aggregate dependencies)
>>> - a class name : this class name is used as default-implementation. 
>>> So, an instance of this class is created. This class must implement 
>>> the service interface and you can implement your own behavior.
>>>
>>> So, with this temporal dependency you can create a smart proxy 
>>> delegating call to the service and managing the dynamism.
>>>
>>> Clement
>>>
>>> -----Original Message-----
>>> From: Richard S. Hall [mailto:heavy@ungoverned.org] Sent: vendredi 
>>> 17 octobre 2008 15:26
>>> To: users@felix.apache.org
>>> Subject: Re: Dependency Injection with annotations
>>>
>>> Miroslav Nachev wrote:
>>>  
>>>> Hello Clement,
>>>>
>>>> In traditional way if I have some OSGi Service which have to be 
>>>> used in some class (POJO Bean) I MUST pass this service to one or 
>>>> more classes as parameter. Then when the time for using of that 
>>>> service is on the service can be unavailable. Similar problem I 
>>>> will have when I want to stop my bundle. That's why if iPOJO 
>>>> Annotations allow some service to be used inside of the bundle will 
>>>> be perfect. This can be done with Proxy. When I create some new 
>>>> object with new JavaClass(...) and in that object I am declared 
>>>> some OSGi Service using iPOJO Annotation, that service will point 
>>>> to some Proxy which proxy will try to get the service on request. 
>>>> This will guarantee that the service is actual independently how 
>>>> much the service is restarted and updated. In traditional way the 
>>>> application must track all service states and etc. Passing the 
>>>> service as parameter complicate the things.
>>>>
>>>> Did you have some plans iPOJO to support the above scenario?
>>>>     
>>>
>>> I am not totally sure I understand your scenario, but it sounds like 
>>> you want a proxy that only tries to get the service when someone 
>>> tries to use it. iPOJO does not support this type of scenario 
>>> automatically, but it is fairly easy to achieve. Assume you have the 
>>> following service:
>>>
>>>     public interface Foo {
>>>         void doFoo();
>>>     }
>>>
>>> You could create a component like this:
>>>
>>>     import org.apache.felix.ipojo.temporal.Requires;
>>>
>>>     public class MyFooProxy implements Foo {
>>>         @Requires
>>>         private Foo m_foo;
>>>
>>>         public void doFoo() {
>>>             m_foo.doFoo();
>>>         }
>>>     }
>>>
>>> The dependency on m_foo is declared to be temporal, which means that 
>>> it will only try to get the service when it is used. If one is not 
>>> available, it will eventually timeout and throw an exception. Now 
>>> you should be able to pass this "proxy" component to you components 
>>> and they will be able to use the service on demand.
>>>
>>> -> richard
>>>
>>>  
>>>> Regards,
>>>> Miro.
>>>>
>>>>
>>>> clement escoffier wrote:
>>>>   
>>>>> 2008/10/14 Stuart McCulloch <mc...@gmail.com>
>>>>>
>>>>>  
>>>>>     
>>>>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>>>>
>>>>>>          
>>>>>>> Hi,
>>>>>>>
>>>>>>> This is very interesting and I will try it but this answer is 
>>>>>>> half of my
>>>>>>> question. I am interesting how to get some service in my code, 
>>>>>>> not in
>>>>>>> another service. For example:
>>>>>>>
>>>>>>> public class SomePOJOBean
>>>>>>> {
>>>>>>>
>>>>>>>   @Requires
>>>>>>>   ??? how to pass some parameters to the service (passive, 
>>>>>>> dynamics)
>>>>>>>   private FooService foo;
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>> How can be implemented the above scenario?
>>>>>>>                 
>>>>> So, as I understand, you don't want (global) services but your own
>>>>> (customized) service. As you're configuring the service, this 
>>>>> service should
>>>>> not be available to other consumers. In iPOJO you can do this by 
>>>>> using
>>>>> composites (the new documentation is coming soon). Composites 
>>>>> assert that
>>>>> your service is isolated. However, composites does not allows you 
>>>>> to declare
>>>>> those services in your code.
>>>>>
>>>>>
>>>>>  
>>>>>     
>>>>>> Well, iPOJO injects components - but these are not necessarily 
>>>>>> services.
>>>>>>
>>>>>> Clement's example happened to provide a service, but this isn't 
>>>>>> mandatory.
>>>>>> You do need to tell iPOJO about your code somehow, and in iPOJO 
>>>>>> this is
>>>>>> done
>>>>>> by marking them as components which iPOJO injects as necessary. 
>>>>>> (I'm sure
>>>>>> Clement can explain this better than me!)
>>>>>>             
>>>>> Service providing is (of course) not necessary. Your component can 
>>>>> be a
>>>>> component that does not provide a service (like a GUI).
>>>>>
>>>>>
>>>>> Clement
>>>>>
>>>>>
>>>>>  
>>>>>     
>>>>>> There are also alternative ways to inject OSGi services, using 
>>>>>> (non-OSGi)
>>>>>> dependency injection frameworks:
>>>>>>
>>>>>>  * Spring has the Spring-DM extension, but I don't know if it fully
>>>>>> supports
>>>>>> configuration via annotation.
>>>>>>
>>>>>>   http://www.springframework.org/osgi/
>>>>>>
>>>>>>  * Guice has the peaberry extension, which I work on - in this 
>>>>>> case the
>>>>>> service configuration is done in the binding module, not the 
>>>>>> annotation (I
>>>>>> did look at doing annotation configuration, but this rapidly 
>>>>>> becomes a
>>>>>> management nightmare)
>>>>>>
>>>>>>   http://code.google.com/p/peaberry/
>>>>>>
>>>>>> HTH
>>>>>>
>>>>>> Regards,
>>>>>>          
>>>>>>> Miro.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> clement escoffier wrote:
>>>>>>>
>>>>>>>              
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> iPOJO provides such annotations as:
>>>>>>>> @Component
>>>>>>>> @Provides // Provides a service
>>>>>>>> public class Foo implements Service {
>>>>>>>>    @Requires // Service dependency
>>>>>>>>    private HelloService hello;
>>>>>>>>
>>>>>>>>
>>>>>>>>    ...
>>>>>>>> }
>>>>>>>>
>>>>>>>> You can find further info at
>>>>>>>> http://felix.apache.org/site/how-to-use-ipojo-annotations.html
>>>>>>>>
>>>>>>>> About parameters, the iPOJO's way is to inject instance 
>>>>>>>> property. Those
>>>>>>>> fields will be set before the execution of your constructor 
>>>>>>>> (between the
>>>>>>>> super constructor invocation and the constructor code), and your
>>>>>>>> constructor
>>>>>>>> can use those fields, such as in:
>>>>>>>>
>>>>>>>> @Component
>>>>>>>> @Provides // Provides a service
>>>>>>>> public class Foo implements Service {
>>>>>>>>
>>>>>>>>    @Property
>>>>>>>>    private String myString;
>>>>>>>>
>>>>>>>>    @Requires // Service dependency
>>>>>>>>    private HelloService hello;
>>>>>>>>
>>>>>>>>    public Foo() {
>>>>>>>>      // Can use myString here as well as hello
>>>>>>>>    }
>>>>>>>>    ...
>>>>>>>> }
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>>
>>>>>>>> Clement
>>>>>>>>
>>>>>>>>
>>>>>>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>                  
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I would like to ask you about some way in Felix to export 
>>>>>>>>> services in
>>>>>>>>> more
>>>>>>>>> easy way only with annotation like in EJB3.x: @Stateful, 
>>>>>>>>> @Stateless,
>>>>>>>>> @Remote, @Local, @EJB, etc.
>>>>>>>>> In my opinion the best way this to be done is inside of the OSGi
>>>>>>>>> framework.
>>>>>>>>> Then all resources (services) can be exported to the framework 
>>>>>>>>> just
>>>>>>>>>                         
>>>>>> with
>>>>>>          
>>>>>>>>> annotation. The same for needed services. What about if before 
>>>>>>>>> to get
>>>>>>>>> some
>>>>>>>>> service we have to pass some parameters to the constructor?
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>> Miro.
>>>>>>>>>
>>>>>>>>> --------------------------------------------------------------------- 
>>>>>>>>>
>>>>>>>>> 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
>>>>>>>
>>>>>>>
>>>>>>>                 
>>>>>> -- 
>>>>>> Cheers, Stuart
>>>>>>
>>>>>>             
>>>>>         
>>>> ---------------------------------------------------------------------
>>>> 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
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>
> ---------------------------------------------------------------------
> 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


Re: Dependency Injection with annotations

Posted by "Richard S. Hall" <he...@ungoverned.org>.
Miroslav Nachev wrote:
> In "Hello Service Client using Annotations" project I am added the 
> following class:
> package ipojo.example;
> import ipojo.example.hello.Hello;
> import org.apache.felix.ipojo.annotations.Requires;
> public class ExtraBean
> {
>    @Requires
>    private Hello[] m_hello;
>
>    public ExtraBean()
>    {
>        System.out.println("ExtraBean.m_hello: " + m_hello);
>    }
>
>    public String doWork()
>    {
>        return "Miro";
>    }
>
> }
>
> Then I use that class in HelloClient.invokeHelloServices() as follow:
>        ExtraBean extraBean = new ExtraBean();
>        System.out.println("extraBean.doWork(): " + extraBean.doWork());

iPOJO does not support this use case, since you want to create the 
instance yourself. For iPOJO to manage the instance, it must create it. 
You could perhaps get around this by using iPOJO factories to create 
your instance:

    http://felix.apache.org/site/how-to-use-ipojo-factories.html

>
> The error result when the bundle is started is:
> ERROR: Error starting 
> file:../hello.client.annotation/target/hello.client.annotation-0.8.0-SNAPSHOT.jar 
> (org.osgi.framework.BundleException: Unresolved constraint in bundle 
> 10: package; (package=ipojo.example))
> org.osgi.framework.BundleException: Unresolved constraint in bundle 
> 10: package; (package=ipojo.example)
>        at 
> org.apache.felix.framework.Felix._resolveBundle(Felix.java:1741)
>        at org.apache.felix.framework.Felix._startBundle(Felix.java:1604)
>        at org.apache.felix.framework.Felix.startBundle(Felix.java:1548)
>        at 
> org.apache.felix.framework.Felix.setFrameworkStartLevel(Felix.java:1142)
>        at 
> org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:265)
>        at java.lang.Thread.run(Unknown Source)

Perhaps your service object is not exporting this package? But the use 
case is still not going to work.

-> richard
>
>
> Miro.
>
>
> Clement Escoffier wrote:
>> Hi,
>> I will complete a little Richard's answer :-):
>> The temporal dependency accepts several arguments:
>> - timeout : setting the timeout time
>> - onTimeout : defines the action to do when the timeout occurs.
>>
>> When requesting a temporal dependency, the thread is stopped until 
>> the service appears or the timeout is reached (3s by default, set the 
>> timeout to -1 to wait forever). When the timeout is reached, you can 
>> define an action. By default a RuntimeException is thrown. But, you 
>> can set the onTimeout action to do:
>> - null: injects null
>> - nullable: injects a fake service object that does nothing
>> - empty-array: injects an empty array (only for aggregate dependencies)
>> - a class name : this class name is used as default-implementation. 
>> So, an instance of this class is created. This class must implement 
>> the service interface and you can implement your own behavior.
>>
>> So, with this temporal dependency you can create a smart proxy 
>> delegating call to the service and managing the dynamism.
>>
>> Clement
>>
>> -----Original Message-----
>> From: Richard S. Hall [mailto:heavy@ungoverned.org] Sent: vendredi 17 
>> octobre 2008 15:26
>> To: users@felix.apache.org
>> Subject: Re: Dependency Injection with annotations
>>
>> Miroslav Nachev wrote:
>>  
>>> Hello Clement,
>>>
>>> In traditional way if I have some OSGi Service which have to be used 
>>> in some class (POJO Bean) I MUST pass this service to one or more 
>>> classes as parameter. Then when the time for using of that service 
>>> is on the service can be unavailable. Similar problem I will have 
>>> when I want to stop my bundle. That's why if iPOJO Annotations allow 
>>> some service to be used inside of the bundle will be perfect. This 
>>> can be done with Proxy. When I create some new object with new 
>>> JavaClass(...) and in that object I am declared some OSGi Service 
>>> using iPOJO Annotation, that service will point to some Proxy which 
>>> proxy will try to get the service on request. This will guarantee 
>>> that the service is actual independently how much the service is 
>>> restarted and updated. In traditional way the application must track 
>>> all service states and etc. Passing the service as parameter 
>>> complicate the things.
>>>
>>> Did you have some plans iPOJO to support the above scenario?
>>>     
>>
>> I am not totally sure I understand your scenario, but it sounds like 
>> you want a proxy that only tries to get the service when someone 
>> tries to use it. iPOJO does not support this type of scenario 
>> automatically, but it is fairly easy to achieve. Assume you have the 
>> following service:
>>
>>     public interface Foo {
>>         void doFoo();
>>     }
>>
>> You could create a component like this:
>>
>>     import org.apache.felix.ipojo.temporal.Requires;
>>
>>     public class MyFooProxy implements Foo {
>>         @Requires
>>         private Foo m_foo;
>>
>>         public void doFoo() {
>>             m_foo.doFoo();
>>         }
>>     }
>>
>> The dependency on m_foo is declared to be temporal, which means that 
>> it will only try to get the service when it is used. If one is not 
>> available, it will eventually timeout and throw an exception. Now you 
>> should be able to pass this "proxy" component to you components and 
>> they will be able to use the service on demand.
>>
>> -> richard
>>
>>  
>>> Regards,
>>> Miro.
>>>
>>>
>>> clement escoffier wrote:
>>>    
>>>> 2008/10/14 Stuart McCulloch <mc...@gmail.com>
>>>>
>>>>  
>>>>      
>>>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>>>
>>>>>           
>>>>>> Hi,
>>>>>>
>>>>>> This is very interesting and I will try it but this answer is 
>>>>>> half of my
>>>>>> question. I am interesting how to get some service in my code, 
>>>>>> not in
>>>>>> another service. For example:
>>>>>>
>>>>>> public class SomePOJOBean
>>>>>> {
>>>>>>
>>>>>>   @Requires
>>>>>>   ??? how to pass some parameters to the service (passive, dynamics)
>>>>>>   private FooService foo;
>>>>>>
>>>>>> }
>>>>>>
>>>>>> How can be implemented the above scenario?
>>>>>>                 
>>>> So, as I understand, you don't want (global) services but your own
>>>> (customized) service. As you're configuring the service, this 
>>>> service should
>>>> not be available to other consumers. In iPOJO you can do this by using
>>>> composites (the new documentation is coming soon). Composites 
>>>> assert that
>>>> your service is isolated. However, composites does not allows you 
>>>> to declare
>>>> those services in your code.
>>>>
>>>>
>>>>  
>>>>      
>>>>> Well, iPOJO injects components - but these are not necessarily 
>>>>> services.
>>>>>
>>>>> Clement's example happened to provide a service, but this isn't 
>>>>> mandatory.
>>>>> You do need to tell iPOJO about your code somehow, and in iPOJO 
>>>>> this is
>>>>> done
>>>>> by marking them as components which iPOJO injects as necessary. 
>>>>> (I'm sure
>>>>> Clement can explain this better than me!)
>>>>>             
>>>> Service providing is (of course) not necessary. Your component can 
>>>> be a
>>>> component that does not provide a service (like a GUI).
>>>>
>>>>
>>>> Clement
>>>>
>>>>
>>>>  
>>>>      
>>>>> There are also alternative ways to inject OSGi services, using 
>>>>> (non-OSGi)
>>>>> dependency injection frameworks:
>>>>>
>>>>>  * Spring has the Spring-DM extension, but I don't know if it fully
>>>>> supports
>>>>> configuration via annotation.
>>>>>
>>>>>   http://www.springframework.org/osgi/
>>>>>
>>>>>  * Guice has the peaberry extension, which I work on - in this 
>>>>> case the
>>>>> service configuration is done in the binding module, not the 
>>>>> annotation (I
>>>>> did look at doing annotation configuration, but this rapidly 
>>>>> becomes a
>>>>> management nightmare)
>>>>>
>>>>>   http://code.google.com/p/peaberry/
>>>>>
>>>>> HTH
>>>>>
>>>>> Regards,
>>>>>           
>>>>>> Miro.
>>>>>>
>>>>>>
>>>>>>
>>>>>> clement escoffier wrote:
>>>>>>
>>>>>>               
>>>>>>> Hi,
>>>>>>>
>>>>>>> iPOJO provides such annotations as:
>>>>>>> @Component
>>>>>>> @Provides // Provides a service
>>>>>>> public class Foo implements Service {
>>>>>>>    @Requires // Service dependency
>>>>>>>    private HelloService hello;
>>>>>>>
>>>>>>>
>>>>>>>    ...
>>>>>>> }
>>>>>>>
>>>>>>> You can find further info at
>>>>>>> http://felix.apache.org/site/how-to-use-ipojo-annotations.html
>>>>>>>
>>>>>>> About parameters, the iPOJO's way is to inject instance 
>>>>>>> property. Those
>>>>>>> fields will be set before the execution of your constructor 
>>>>>>> (between the
>>>>>>> super constructor invocation and the constructor code), and your
>>>>>>> constructor
>>>>>>> can use those fields, such as in:
>>>>>>>
>>>>>>> @Component
>>>>>>> @Provides // Provides a service
>>>>>>> public class Foo implements Service {
>>>>>>>
>>>>>>>    @Property
>>>>>>>    private String myString;
>>>>>>>
>>>>>>>    @Requires // Service dependency
>>>>>>>    private HelloService hello;
>>>>>>>
>>>>>>>    public Foo() {
>>>>>>>      // Can use myString here as well as hello
>>>>>>>    }
>>>>>>>    ...
>>>>>>> }
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> Clement
>>>>>>>
>>>>>>>
>>>>>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>                   
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I would like to ask you about some way in Felix to export 
>>>>>>>> services in
>>>>>>>> more
>>>>>>>> easy way only with annotation like in EJB3.x: @Stateful, 
>>>>>>>> @Stateless,
>>>>>>>> @Remote, @Local, @EJB, etc.
>>>>>>>> In my opinion the best way this to be done is inside of the OSGi
>>>>>>>> framework.
>>>>>>>> Then all resources (services) can be exported to the framework 
>>>>>>>> just
>>>>>>>>                         
>>>>> with
>>>>>           
>>>>>>>> annotation. The same for needed services. What about if before 
>>>>>>>> to get
>>>>>>>> some
>>>>>>>> service we have to pass some parameters to the constructor?
>>>>>>>>
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>> Miro.
>>>>>>>>
>>>>>>>> --------------------------------------------------------------------- 
>>>>>>>>
>>>>>>>> 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
>>>>>>
>>>>>>
>>>>>>                 
>>>>> -- 
>>>>> Cheers, Stuart
>>>>>
>>>>>             
>>>>         
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>

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


Re: Dependency Injection with annotations

Posted by Miroslav Nachev <m....@prosyst.bg>.
In "Hello Service Client using Annotations" project I am added the 
following class:
package ipojo.example;
import ipojo.example.hello.Hello;
import org.apache.felix.ipojo.annotations.Requires;
public class ExtraBean
{
    @Requires
    private Hello[] m_hello;

    public ExtraBean()
    {
        System.out.println("ExtraBean.m_hello: " + m_hello);
    }

    public String doWork()
    {
        return "Miro";
    }

}

Then I use that class in HelloClient.invokeHelloServices() as follow:
        ExtraBean extraBean = new ExtraBean();
        System.out.println("extraBean.doWork(): " + extraBean.doWork());

The error result when the bundle is started is:
ERROR: Error starting 
file:../hello.client.annotation/target/hello.client.annotation-0.8.0-SNAPSHOT.jar 
(org.osgi.framework.BundleException: Unresolved constraint in bundle 10: 
package; (package=ipojo.example))
org.osgi.framework.BundleException: Unresolved constraint in bundle 10: 
package; (package=ipojo.example)
        at org.apache.felix.framework.Felix._resolveBundle(Felix.java:1741)
        at org.apache.felix.framework.Felix._startBundle(Felix.java:1604)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1548)
        at 
org.apache.felix.framework.Felix.setFrameworkStartLevel(Felix.java:1142)
        at 
org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:265)
        at java.lang.Thread.run(Unknown Source)


Miro.


Clement Escoffier wrote:
> Hi, 
>
> I will complete a little Richard's answer :-):
> The temporal dependency accepts several arguments:
> - timeout : setting the timeout time
> - onTimeout : defines the action to do when the timeout occurs.
>
> When requesting a temporal dependency, the thread is stopped until the service appears or the timeout is reached (3s by default, set the timeout to -1 to wait forever). When the timeout is reached, you can define an action. By default a RuntimeException is thrown. But, you can set the onTimeout action to do:
> - null: injects null
> - nullable: injects a fake service object that does nothing
> - empty-array: injects an empty array (only for aggregate dependencies)
> - a class name : this class name is used as default-implementation. So, an instance of this class is created. This class must implement the service interface and you can implement your own behavior. 
>
>
> So, with this temporal dependency you can create a smart proxy delegating call to the service and managing the dynamism.
>
> Clement
>
> -----Original Message-----
> From: Richard S. Hall [mailto:heavy@ungoverned.org] 
> Sent: vendredi 17 octobre 2008 15:26
> To: users@felix.apache.org
> Subject: Re: Dependency Injection with annotations
>
> Miroslav Nachev wrote:
>   
>> Hello Clement,
>>
>> In traditional way if I have some OSGi Service which have to be used 
>> in some class (POJO Bean) I MUST pass this service to one or more 
>> classes as parameter. Then when the time for using of that service is 
>> on the service can be unavailable. Similar problem I will have when I 
>> want to stop my bundle. That's why if iPOJO Annotations allow some 
>> service to be used inside of the bundle will be perfect. This can be 
>> done with Proxy. When I create some new object with new JavaClass(...) 
>> and in that object I am declared some OSGi Service using iPOJO 
>> Annotation, that service will point to some Proxy which proxy will try 
>> to get the service on request. This will guarantee that the service is 
>> actual independently how much the service is restarted and updated. In 
>> traditional way the application must track all service states and etc. 
>> Passing the service as parameter complicate the things.
>>
>> Did you have some plans iPOJO to support the above scenario?
>>     
>
> I am not totally sure I understand your scenario, but it sounds like you 
> want a proxy that only tries to get the service when someone tries to 
> use it. iPOJO does not support this type of scenario automatically, but 
> it is fairly easy to achieve. Assume you have the following service:
>
>     public interface Foo {
>         void doFoo();
>     }
>
> You could create a component like this:
>
>     import org.apache.felix.ipojo.temporal.Requires;
>
>     public class MyFooProxy implements Foo {
>         @Requires
>         private Foo m_foo;
>
>         public void doFoo() {
>             m_foo.doFoo();
>         }
>     }
>
> The dependency on m_foo is declared to be temporal, which means that it 
> will only try to get the service when it is used. If one is not 
> available, it will eventually timeout and throw an exception. Now you 
> should be able to pass this "proxy" component to you components and they 
> will be able to use the service on demand.
>
> -> richard
>
>   
>> Regards,
>> Miro.
>>
>>
>> clement escoffier wrote:
>>     
>>> 2008/10/14 Stuart McCulloch <mc...@gmail.com>
>>>
>>>  
>>>       
>>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>>
>>>>    
>>>>         
>>>>> Hi,
>>>>>
>>>>> This is very interesting and I will try it but this answer is half 
>>>>> of my
>>>>> question. I am interesting how to get some service in my code, not in
>>>>> another service. For example:
>>>>>
>>>>> public class SomePOJOBean
>>>>> {
>>>>>
>>>>>   @Requires
>>>>>   ??? how to pass some parameters to the service (passive, dynamics)
>>>>>   private FooService foo;
>>>>>
>>>>> }
>>>>>
>>>>> How can be implemented the above scenario?
>>>>>       
>>>>>           
>>> So, as I understand, you don't want (global) services but your own
>>> (customized) service. As you're configuring the service, this service 
>>> should
>>> not be available to other consumers. In iPOJO you can do this by using
>>> composites (the new documentation is coming soon). Composites assert 
>>> that
>>> your service is isolated. However, composites does not allows you to 
>>> declare
>>> those services in your code.
>>>
>>>
>>>  
>>>       
>>>> Well, iPOJO injects components - but these are not necessarily 
>>>> services.
>>>>
>>>> Clement's example happened to provide a service, but this isn't 
>>>> mandatory.
>>>> You do need to tell iPOJO about your code somehow, and in iPOJO this is
>>>> done
>>>> by marking them as components which iPOJO injects as necessary. (I'm 
>>>> sure
>>>> Clement can explain this better than me!)
>>>>     
>>>>         
>>> Service providing is (of course) not necessary. Your component can be a
>>> component that does not provide a service (like a GUI).
>>>
>>>
>>> Clement
>>>
>>>
>>>  
>>>       
>>>> There are also alternative ways to inject OSGi services, using 
>>>> (non-OSGi)
>>>> dependency injection frameworks:
>>>>
>>>>  * Spring has the Spring-DM extension, but I don't know if it fully
>>>> supports
>>>> configuration via annotation.
>>>>
>>>>   http://www.springframework.org/osgi/
>>>>
>>>>  * Guice has the peaberry extension, which I work on - in this case the
>>>> service configuration is done in the binding module, not the 
>>>> annotation (I
>>>> did look at doing annotation configuration, but this rapidly becomes a
>>>> management nightmare)
>>>>
>>>>   http://code.google.com/p/peaberry/
>>>>
>>>> HTH
>>>>
>>>> Regards,
>>>>    
>>>>         
>>>>> Miro.
>>>>>
>>>>>
>>>>>
>>>>> clement escoffier wrote:
>>>>>
>>>>>      
>>>>>           
>>>>>> Hi,
>>>>>>
>>>>>> iPOJO provides such annotations as:
>>>>>> @Component
>>>>>> @Provides // Provides a service
>>>>>> public class Foo implements Service {
>>>>>>    @Requires // Service dependency
>>>>>>    private HelloService hello;
>>>>>>
>>>>>>
>>>>>>    ...
>>>>>> }
>>>>>>
>>>>>> You can find further info at
>>>>>> http://felix.apache.org/site/how-to-use-ipojo-annotations.html
>>>>>>
>>>>>> About parameters, the iPOJO's way is to inject instance property. 
>>>>>> Those
>>>>>> fields will be set before the execution of your constructor 
>>>>>> (between the
>>>>>> super constructor invocation and the constructor code), and your
>>>>>> constructor
>>>>>> can use those fields, such as in:
>>>>>>
>>>>>> @Component
>>>>>> @Provides // Provides a service
>>>>>> public class Foo implements Service {
>>>>>>
>>>>>>    @Property
>>>>>>    private String myString;
>>>>>>
>>>>>>    @Requires // Service dependency
>>>>>>    private HelloService hello;
>>>>>>
>>>>>>    public Foo() {
>>>>>>      // Can use myString here as well as hello
>>>>>>    }
>>>>>>    ...
>>>>>> }
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Clement
>>>>>>
>>>>>>
>>>>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>>>>
>>>>>>
>>>>>>
>>>>>>        
>>>>>>             
>>>>>>> Hi,
>>>>>>>
>>>>>>> I would like to ask you about some way in Felix to export 
>>>>>>> services in
>>>>>>> more
>>>>>>> easy way only with annotation like in EJB3.x: @Stateful, @Stateless,
>>>>>>> @Remote, @Local, @EJB, etc.
>>>>>>> In my opinion the best way this to be done is inside of the OSGi
>>>>>>> framework.
>>>>>>> Then all resources (services) can be exported to the framework just
>>>>>>>           
>>>>>>>               
>>>> with
>>>>    
>>>>         
>>>>>>> annotation. The same for needed services. What about if before to 
>>>>>>> get
>>>>>>> some
>>>>>>> service we have to pass some parameters to the constructor?
>>>>>>>
>>>>>>>
>>>>>>> Regards,
>>>>>>> Miro.
>>>>>>>
>>>>>>> --------------------------------------------------------------------- 
>>>>>>>
>>>>>>> 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
>>>>>
>>>>>
>>>>>       
>>>>>           
>>>> -- 
>>>> Cheers, Stuart
>>>>
>>>>     
>>>>         
>>>   
>>>       
>> ---------------------------------------------------------------------
>> 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
>
>
>
> ---------------------------------------------------------------------
> 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


RE: Dependency Injection with annotations

Posted by Clement Escoffier <cl...@gmail.com>.
Hi, 

I will complete a little Richard's answer :-):
The temporal dependency accepts several arguments:
- timeout : setting the timeout time
- onTimeout : defines the action to do when the timeout occurs.

When requesting a temporal dependency, the thread is stopped until the service appears or the timeout is reached (3s by default, set the timeout to -1 to wait forever). When the timeout is reached, you can define an action. By default a RuntimeException is thrown. But, you can set the onTimeout action to do:
- null: injects null
- nullable: injects a fake service object that does nothing
- empty-array: injects an empty array (only for aggregate dependencies)
- a class name : this class name is used as default-implementation. So, an instance of this class is created. This class must implement the service interface and you can implement your own behavior. 


So, with this temporal dependency you can create a smart proxy delegating call to the service and managing the dynamism.

Clement

-----Original Message-----
From: Richard S. Hall [mailto:heavy@ungoverned.org] 
Sent: vendredi 17 octobre 2008 15:26
To: users@felix.apache.org
Subject: Re: Dependency Injection with annotations

Miroslav Nachev wrote:
> Hello Clement,
>
> In traditional way if I have some OSGi Service which have to be used 
> in some class (POJO Bean) I MUST pass this service to one or more 
> classes as parameter. Then when the time for using of that service is 
> on the service can be unavailable. Similar problem I will have when I 
> want to stop my bundle. That's why if iPOJO Annotations allow some 
> service to be used inside of the bundle will be perfect. This can be 
> done with Proxy. When I create some new object with new JavaClass(...) 
> and in that object I am declared some OSGi Service using iPOJO 
> Annotation, that service will point to some Proxy which proxy will try 
> to get the service on request. This will guarantee that the service is 
> actual independently how much the service is restarted and updated. In 
> traditional way the application must track all service states and etc. 
> Passing the service as parameter complicate the things.
>
> Did you have some plans iPOJO to support the above scenario?

I am not totally sure I understand your scenario, but it sounds like you 
want a proxy that only tries to get the service when someone tries to 
use it. iPOJO does not support this type of scenario automatically, but 
it is fairly easy to achieve. Assume you have the following service:

    public interface Foo {
        void doFoo();
    }

You could create a component like this:

    import org.apache.felix.ipojo.temporal.Requires;

    public class MyFooProxy implements Foo {
        @Requires
        private Foo m_foo;

        public void doFoo() {
            m_foo.doFoo();
        }
    }

The dependency on m_foo is declared to be temporal, which means that it 
will only try to get the service when it is used. If one is not 
available, it will eventually timeout and throw an exception. Now you 
should be able to pass this "proxy" component to you components and they 
will be able to use the service on demand.

-> richard

>
>
> Regards,
> Miro.
>
>
> clement escoffier wrote:
>> 2008/10/14 Stuart McCulloch <mc...@gmail.com>
>>
>>  
>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>
>>>    
>>>> Hi,
>>>>
>>>> This is very interesting and I will try it but this answer is half 
>>>> of my
>>>> question. I am interesting how to get some service in my code, not in
>>>> another service. For example:
>>>>
>>>> public class SomePOJOBean
>>>> {
>>>>
>>>>   @Requires
>>>>   ??? how to pass some parameters to the service (passive, dynamics)
>>>>   private FooService foo;
>>>>
>>>> }
>>>>
>>>> How can be implemented the above scenario?
>>>>       
>>
>> So, as I understand, you don't want (global) services but your own
>> (customized) service. As you're configuring the service, this service 
>> should
>> not be available to other consumers. In iPOJO you can do this by using
>> composites (the new documentation is coming soon). Composites assert 
>> that
>> your service is isolated. However, composites does not allows you to 
>> declare
>> those services in your code.
>>
>>
>>  
>>> Well, iPOJO injects components - but these are not necessarily 
>>> services.
>>>
>>> Clement's example happened to provide a service, but this isn't 
>>> mandatory.
>>> You do need to tell iPOJO about your code somehow, and in iPOJO this is
>>> done
>>> by marking them as components which iPOJO injects as necessary. (I'm 
>>> sure
>>> Clement can explain this better than me!)
>>>     
>>
>>
>> Service providing is (of course) not necessary. Your component can be a
>> component that does not provide a service (like a GUI).
>>
>>
>> Clement
>>
>>
>>  
>>> There are also alternative ways to inject OSGi services, using 
>>> (non-OSGi)
>>> dependency injection frameworks:
>>>
>>>  * Spring has the Spring-DM extension, but I don't know if it fully
>>> supports
>>> configuration via annotation.
>>>
>>>   http://www.springframework.org/osgi/
>>>
>>>  * Guice has the peaberry extension, which I work on - in this case the
>>> service configuration is done in the binding module, not the 
>>> annotation (I
>>> did look at doing annotation configuration, but this rapidly becomes a
>>> management nightmare)
>>>
>>>   http://code.google.com/p/peaberry/
>>>
>>> HTH
>>>
>>> Regards,
>>>    
>>>> Miro.
>>>>
>>>>
>>>>
>>>> clement escoffier wrote:
>>>>
>>>>      
>>>>> Hi,
>>>>>
>>>>> iPOJO provides such annotations as:
>>>>> @Component
>>>>> @Provides // Provides a service
>>>>> public class Foo implements Service {
>>>>>    @Requires // Service dependency
>>>>>    private HelloService hello;
>>>>>
>>>>>
>>>>>    ...
>>>>> }
>>>>>
>>>>> You can find further info at
>>>>> http://felix.apache.org/site/how-to-use-ipojo-annotations.html
>>>>>
>>>>> About parameters, the iPOJO's way is to inject instance property. 
>>>>> Those
>>>>> fields will be set before the execution of your constructor 
>>>>> (between the
>>>>> super constructor invocation and the constructor code), and your
>>>>> constructor
>>>>> can use those fields, such as in:
>>>>>
>>>>> @Component
>>>>> @Provides // Provides a service
>>>>> public class Foo implements Service {
>>>>>
>>>>>    @Property
>>>>>    private String myString;
>>>>>
>>>>>    @Requires // Service dependency
>>>>>    private HelloService hello;
>>>>>
>>>>>    public Foo() {
>>>>>      // Can use myString here as well as hello
>>>>>    }
>>>>>    ...
>>>>> }
>>>>>
>>>>> Regards,
>>>>>
>>>>> Clement
>>>>>
>>>>>
>>>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>>>
>>>>>
>>>>>
>>>>>        
>>>>>> Hi,
>>>>>>
>>>>>> I would like to ask you about some way in Felix to export 
>>>>>> services in
>>>>>> more
>>>>>> easy way only with annotation like in EJB3.x: @Stateful, @Stateless,
>>>>>> @Remote, @Local, @EJB, etc.
>>>>>> In my opinion the best way this to be done is inside of the OSGi
>>>>>> framework.
>>>>>> Then all resources (services) can be exported to the framework just
>>>>>>           
>>> with
>>>    
>>>>>> annotation. The same for needed services. What about if before to 
>>>>>> get
>>>>>> some
>>>>>> service we have to pass some parameters to the constructor?
>>>>>>
>>>>>>
>>>>>> Regards,
>>>>>> Miro.
>>>>>>
>>>>>> --------------------------------------------------------------------- 
>>>>>>
>>>>>> 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
>>>>
>>>>
>>>>       
>>> -- 
>>> Cheers, Stuart
>>>
>>>     
>>
>>   
>
>
> ---------------------------------------------------------------------
> 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



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


Re: Dependency Injection with annotations

Posted by "Richard S. Hall" <he...@ungoverned.org>.
Miroslav Nachev wrote:
> Hello Clement,
>
> In traditional way if I have some OSGi Service which have to be used 
> in some class (POJO Bean) I MUST pass this service to one or more 
> classes as parameter. Then when the time for using of that service is 
> on the service can be unavailable. Similar problem I will have when I 
> want to stop my bundle. That's why if iPOJO Annotations allow some 
> service to be used inside of the bundle will be perfect. This can be 
> done with Proxy. When I create some new object with new JavaClass(...) 
> and in that object I am declared some OSGi Service using iPOJO 
> Annotation, that service will point to some Proxy which proxy will try 
> to get the service on request. This will guarantee that the service is 
> actual independently how much the service is restarted and updated. In 
> traditional way the application must track all service states and etc. 
> Passing the service as parameter complicate the things.
>
> Did you have some plans iPOJO to support the above scenario?

I am not totally sure I understand your scenario, but it sounds like you 
want a proxy that only tries to get the service when someone tries to 
use it. iPOJO does not support this type of scenario automatically, but 
it is fairly easy to achieve. Assume you have the following service:

    public interface Foo {
        void doFoo();
    }

You could create a component like this:

    import org.apache.felix.ipojo.temporal.Requires;

    public class MyFooProxy implements Foo {
        @Requires
        private Foo m_foo;

        public void doFoo() {
            m_foo.doFoo();
        }
    }

The dependency on m_foo is declared to be temporal, which means that it 
will only try to get the service when it is used. If one is not 
available, it will eventually timeout and throw an exception. Now you 
should be able to pass this "proxy" component to you components and they 
will be able to use the service on demand.

-> richard

>
>
> Regards,
> Miro.
>
>
> clement escoffier wrote:
>> 2008/10/14 Stuart McCulloch <mc...@gmail.com>
>>
>>  
>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>
>>>    
>>>> Hi,
>>>>
>>>> This is very interesting and I will try it but this answer is half 
>>>> of my
>>>> question. I am interesting how to get some service in my code, not in
>>>> another service. For example:
>>>>
>>>> public class SomePOJOBean
>>>> {
>>>>
>>>>   @Requires
>>>>   ??? how to pass some parameters to the service (passive, dynamics)
>>>>   private FooService foo;
>>>>
>>>> }
>>>>
>>>> How can be implemented the above scenario?
>>>>       
>>
>> So, as I understand, you don't want (global) services but your own
>> (customized) service. As you're configuring the service, this service 
>> should
>> not be available to other consumers. In iPOJO you can do this by using
>> composites (the new documentation is coming soon). Composites assert 
>> that
>> your service is isolated. However, composites does not allows you to 
>> declare
>> those services in your code.
>>
>>
>>  
>>> Well, iPOJO injects components - but these are not necessarily 
>>> services.
>>>
>>> Clement's example happened to provide a service, but this isn't 
>>> mandatory.
>>> You do need to tell iPOJO about your code somehow, and in iPOJO this is
>>> done
>>> by marking them as components which iPOJO injects as necessary. (I'm 
>>> sure
>>> Clement can explain this better than me!)
>>>     
>>
>>
>> Service providing is (of course) not necessary. Your component can be a
>> component that does not provide a service (like a GUI).
>>
>>
>> Clement
>>
>>
>>  
>>> There are also alternative ways to inject OSGi services, using 
>>> (non-OSGi)
>>> dependency injection frameworks:
>>>
>>>  * Spring has the Spring-DM extension, but I don't know if it fully
>>> supports
>>> configuration via annotation.
>>>
>>>   http://www.springframework.org/osgi/
>>>
>>>  * Guice has the peaberry extension, which I work on - in this case the
>>> service configuration is done in the binding module, not the 
>>> annotation (I
>>> did look at doing annotation configuration, but this rapidly becomes a
>>> management nightmare)
>>>
>>>   http://code.google.com/p/peaberry/
>>>
>>> HTH
>>>
>>> Regards,
>>>    
>>>> Miro.
>>>>
>>>>
>>>>
>>>> clement escoffier wrote:
>>>>
>>>>      
>>>>> Hi,
>>>>>
>>>>> iPOJO provides such annotations as:
>>>>> @Component
>>>>> @Provides // Provides a service
>>>>> public class Foo implements Service {
>>>>>    @Requires // Service dependency
>>>>>    private HelloService hello;
>>>>>
>>>>>
>>>>>    ...
>>>>> }
>>>>>
>>>>> You can find further info at
>>>>> http://felix.apache.org/site/how-to-use-ipojo-annotations.html
>>>>>
>>>>> About parameters, the iPOJO's way is to inject instance property. 
>>>>> Those
>>>>> fields will be set before the execution of your constructor 
>>>>> (between the
>>>>> super constructor invocation and the constructor code), and your
>>>>> constructor
>>>>> can use those fields, such as in:
>>>>>
>>>>> @Component
>>>>> @Provides // Provides a service
>>>>> public class Foo implements Service {
>>>>>
>>>>>    @Property
>>>>>    private String myString;
>>>>>
>>>>>    @Requires // Service dependency
>>>>>    private HelloService hello;
>>>>>
>>>>>    public Foo() {
>>>>>      // Can use myString here as well as hello
>>>>>    }
>>>>>    ...
>>>>> }
>>>>>
>>>>> Regards,
>>>>>
>>>>> Clement
>>>>>
>>>>>
>>>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>>>
>>>>>
>>>>>
>>>>>        
>>>>>> Hi,
>>>>>>
>>>>>> I would like to ask you about some way in Felix to export 
>>>>>> services in
>>>>>> more
>>>>>> easy way only with annotation like in EJB3.x: @Stateful, @Stateless,
>>>>>> @Remote, @Local, @EJB, etc.
>>>>>> In my opinion the best way this to be done is inside of the OSGi
>>>>>> framework.
>>>>>> Then all resources (services) can be exported to the framework just
>>>>>>           
>>> with
>>>    
>>>>>> annotation. The same for needed services. What about if before to 
>>>>>> get
>>>>>> some
>>>>>> service we have to pass some parameters to the constructor?
>>>>>>
>>>>>>
>>>>>> Regards,
>>>>>> Miro.
>>>>>>
>>>>>> --------------------------------------------------------------------- 
>>>>>>
>>>>>> 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
>>>>
>>>>
>>>>       
>>> -- 
>>> Cheers, Stuart
>>>
>>>     
>>
>>   
>
>
> ---------------------------------------------------------------------
> 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


Re: Dependency Injection with annotations

Posted by Miroslav Nachev <m....@prosyst.bg>.
Hello Clement,

In traditional way if I have some OSGi Service which have to be used in 
some class (POJO Bean) I MUST pass this service to one or more classes 
as parameter. Then when the time for using of that service is on the 
service can be unavailable. Similar problem I will have when I want to 
stop my bundle. That's why if iPOJO Annotations allow some service to be 
used inside of the bundle will be perfect. This can be done with Proxy. 
When I create some new object with new JavaClass(...) and in that object 
I am declared some OSGi Service using iPOJO Annotation, that service 
will point to some Proxy which proxy will try to get the service on 
request. This will guarantee that the service is actual independently 
how much the service is restarted and updated. In traditional way the 
application must track all service states and etc. Passing the service 
as parameter complicate the things.

Did you have some plans iPOJO to support the above scenario?


Regards,
Miro.


clement escoffier wrote:
> 2008/10/14 Stuart McCulloch <mc...@gmail.com>
>
>   
>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>
>>     
>>> Hi,
>>>
>>> This is very interesting and I will try it but this answer is half of my
>>> question. I am interesting how to get some service in my code, not in
>>> another service. For example:
>>>
>>> public class SomePOJOBean
>>> {
>>>
>>>   @Requires
>>>   ??? how to pass some parameters to the service (passive, dynamics)
>>>   private FooService foo;
>>>
>>> }
>>>
>>> How can be implemented the above scenario?
>>>       
>
> So, as I understand, you don't want (global) services but your own
> (customized) service. As you're configuring the service, this service should
> not be available to other consumers. In iPOJO you can do this by using
> composites (the new documentation is coming soon). Composites assert that
> your service is isolated. However, composites does not allows you to declare
> those services in your code.
>
>
>   
>> Well, iPOJO injects components - but these are not necessarily services.
>>
>> Clement's example happened to provide a service, but this isn't mandatory.
>> You do need to tell iPOJO about your code somehow, and in iPOJO this is
>> done
>> by marking them as components which iPOJO injects as necessary. (I'm sure
>> Clement can explain this better than me!)
>>     
>
>
> Service providing is (of course) not necessary. Your component can be a
> component that does not provide a service (like a GUI).
>
>
> Clement
>
>
>   
>> There are also alternative ways to inject OSGi services, using (non-OSGi)
>> dependency injection frameworks:
>>
>>  * Spring has the Spring-DM extension, but I don't know if it fully
>> supports
>> configuration via annotation.
>>
>>   http://www.springframework.org/osgi/
>>
>>  * Guice has the peaberry extension, which I work on - in this case the
>> service configuration is done in the binding module, not the annotation (I
>> did look at doing annotation configuration, but this rapidly becomes a
>> management nightmare)
>>
>>   http://code.google.com/p/peaberry/
>>
>> HTH
>>
>> Regards,
>>     
>>> Miro.
>>>
>>>
>>>
>>> clement escoffier wrote:
>>>
>>>       
>>>> Hi,
>>>>
>>>> iPOJO provides such annotations as:
>>>> @Component
>>>> @Provides // Provides a service
>>>> public class Foo implements Service {
>>>>    @Requires // Service dependency
>>>>    private HelloService hello;
>>>>
>>>>
>>>>    ...
>>>> }
>>>>
>>>> You can find further info at
>>>> http://felix.apache.org/site/how-to-use-ipojo-annotations.html
>>>>
>>>> About parameters, the iPOJO's way is to inject instance property. Those
>>>> fields will be set before the execution of your constructor (between the
>>>> super constructor invocation and the constructor code), and your
>>>> constructor
>>>> can use those fields, such as in:
>>>>
>>>> @Component
>>>> @Provides // Provides a service
>>>> public class Foo implements Service {
>>>>
>>>>    @Property
>>>>    private String myString;
>>>>
>>>>    @Requires // Service dependency
>>>>    private HelloService hello;
>>>>
>>>>    public Foo() {
>>>>      // Can use myString here as well as hello
>>>>    }
>>>>    ...
>>>> }
>>>>
>>>> Regards,
>>>>
>>>> Clement
>>>>
>>>>
>>>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>>>
>>>>
>>>>
>>>>         
>>>>> Hi,
>>>>>
>>>>> I would like to ask you about some way in Felix to export services in
>>>>> more
>>>>> easy way only with annotation like in EJB3.x: @Stateful, @Stateless,
>>>>> @Remote, @Local, @EJB, etc.
>>>>> In my opinion the best way this to be done is inside of the OSGi
>>>>> framework.
>>>>> Then all resources (services) can be exported to the framework just
>>>>>           
>> with
>>     
>>>>> annotation. The same for needed services. What about if before to get
>>>>> some
>>>>> service we have to pass some parameters to the constructor?
>>>>>
>>>>>
>>>>> Regards,
>>>>> Miro.
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> 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
>>>
>>>
>>>       
>> --
>> Cheers, Stuart
>>
>>     
>
>   


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


Re: Dependency Injection with annotations

Posted by clement escoffier <cl...@gmail.com>.
2008/10/14 Stuart McCulloch <mc...@gmail.com>

> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>
> > Hi,
> >
> > This is very interesting and I will try it but this answer is half of my
> > question. I am interesting how to get some service in my code, not in
> > another service. For example:
> >
> > public class SomePOJOBean
> > {
> >
> >   @Requires
> >   ??? how to pass some parameters to the service (passive, dynamics)
> >   private FooService foo;
> >
> > }
> >
> > How can be implemented the above scenario?
>

So, as I understand, you don't want (global) services but your own
(customized) service. As you're configuring the service, this service should
not be available to other consumers. In iPOJO you can do this by using
composites (the new documentation is coming soon). Composites assert that
your service is isolated. However, composites does not allows you to declare
those services in your code.


>
> >
>
> Well, iPOJO injects components - but these are not necessarily services.
>
> Clement's example happened to provide a service, but this isn't mandatory.
> You do need to tell iPOJO about your code somehow, and in iPOJO this is
> done
> by marking them as components which iPOJO injects as necessary. (I'm sure
> Clement can explain this better than me!)


Service providing is (of course) not necessary. Your component can be a
component that does not provide a service (like a GUI).


Clement


>
>
> There are also alternative ways to inject OSGi services, using (non-OSGi)
> dependency injection frameworks:
>
>  * Spring has the Spring-DM extension, but I don't know if it fully
> supports
> configuration via annotation.
>
>   http://www.springframework.org/osgi/
>
>  * Guice has the peaberry extension, which I work on - in this case the
> service configuration is done in the binding module, not the annotation (I
> did look at doing annotation configuration, but this rapidly becomes a
> management nightmare)
>
>   http://code.google.com/p/peaberry/
>
> HTH
>
> Regards,
> > Miro.
> >
> >
> >
> > clement escoffier wrote:
> >
> >> Hi,
> >>
> >> iPOJO provides such annotations as:
> >> @Component
> >> @Provides // Provides a service
> >> public class Foo implements Service {
> >>    @Requires // Service dependency
> >>    private HelloService hello;
> >>
> >>
> >>    ...
> >> }
> >>
> >> You can find further info at
> >> http://felix.apache.org/site/how-to-use-ipojo-annotations.html
> >>
> >> About parameters, the iPOJO's way is to inject instance property. Those
> >> fields will be set before the execution of your constructor (between the
> >> super constructor invocation and the constructor code), and your
> >> constructor
> >> can use those fields, such as in:
> >>
> >> @Component
> >> @Provides // Provides a service
> >> public class Foo implements Service {
> >>
> >>    @Property
> >>    private String myString;
> >>
> >>    @Requires // Service dependency
> >>    private HelloService hello;
> >>
> >>    public Foo() {
> >>      // Can use myString here as well as hello
> >>    }
> >>    ...
> >> }
> >>
> >> Regards,
> >>
> >> Clement
> >>
> >>
> >> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
> >>
> >>
> >>
> >>> Hi,
> >>>
> >>> I would like to ask you about some way in Felix to export services in
> >>> more
> >>> easy way only with annotation like in EJB3.x: @Stateful, @Stateless,
> >>> @Remote, @Local, @EJB, etc.
> >>> In my opinion the best way this to be done is inside of the OSGi
> >>> framework.
> >>> Then all resources (services) can be exported to the framework just
> with
> >>> annotation. The same for needed services. What about if before to get
> >>> some
> >>> service we have to pass some parameters to the constructor?
> >>>
> >>>
> >>> Regards,
> >>> Miro.
> >>>
> >>> ---------------------------------------------------------------------
> >>> 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
> >
> >
>
>
> --
> Cheers, Stuart
>

Re: Dependency Injection with annotations

Posted by Stuart McCulloch <mc...@gmail.com>.
2008/10/14 Miroslav Nachev <m....@prosyst.bg>

> Hi,
>
> This is very interesting and I will try it but this answer is half of my
> question. I am interesting how to get some service in my code, not in
> another service. For example:
>
> public class SomePOJOBean
> {
>
>   @Requires
>   ??? how to pass some parameters to the service (passive, dynamics)
>   private FooService foo;
>
> }
>
> How can be implemented the above scenario?
>

Well, iPOJO injects components - but these are not necessarily services.

Clement's example happened to provide a service, but this isn't mandatory.
You do need to tell iPOJO about your code somehow, and in iPOJO this is done
by marking them as components which iPOJO injects as necessary. (I'm sure
Clement can explain this better than me!)

There are also alternative ways to inject OSGi services, using (non-OSGi)
dependency injection frameworks:

 * Spring has the Spring-DM extension, but I don't know if it fully supports
configuration via annotation.

   http://www.springframework.org/osgi/

 * Guice has the peaberry extension, which I work on - in this case the
service configuration is done in the binding module, not the annotation (I
did look at doing annotation configuration, but this rapidly becomes a
management nightmare)

   http://code.google.com/p/peaberry/

HTH

Regards,
> Miro.
>
>
>
> clement escoffier wrote:
>
>> Hi,
>>
>> iPOJO provides such annotations as:
>> @Component
>> @Provides // Provides a service
>> public class Foo implements Service {
>>    @Requires // Service dependency
>>    private HelloService hello;
>>
>>
>>    ...
>> }
>>
>> You can find further info at
>> http://felix.apache.org/site/how-to-use-ipojo-annotations.html
>>
>> About parameters, the iPOJO's way is to inject instance property. Those
>> fields will be set before the execution of your constructor (between the
>> super constructor invocation and the constructor code), and your
>> constructor
>> can use those fields, such as in:
>>
>> @Component
>> @Provides // Provides a service
>> public class Foo implements Service {
>>
>>    @Property
>>    private String myString;
>>
>>    @Requires // Service dependency
>>    private HelloService hello;
>>
>>    public Foo() {
>>      // Can use myString here as well as hello
>>    }
>>    ...
>> }
>>
>> Regards,
>>
>> Clement
>>
>>
>> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>>
>>
>>
>>> Hi,
>>>
>>> I would like to ask you about some way in Felix to export services in
>>> more
>>> easy way only with annotation like in EJB3.x: @Stateful, @Stateless,
>>> @Remote, @Local, @EJB, etc.
>>> In my opinion the best way this to be done is inside of the OSGi
>>> framework.
>>> Then all resources (services) can be exported to the framework just with
>>> annotation. The same for needed services. What about if before to get
>>> some
>>> service we have to pass some parameters to the constructor?
>>>
>>>
>>> Regards,
>>> Miro.
>>>
>>> ---------------------------------------------------------------------
>>> 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
>
>


-- 
Cheers, Stuart

Re: Dependency Injection with annotations

Posted by Miroslav Nachev <m....@prosyst.bg>.
Hi,

This is very interesting and I will try it but this answer is half of my 
question. I am interesting how to get some service in my code, not in 
another service. For example:

public class SomePOJOBean
{

    @Requires
    ??? how to pass some parameters to the service (passive, dynamics)
    private FooService foo;

}

How can be implemented the above scenario?


Regards,
Miro.


clement escoffier wrote:
> Hi,
>
> iPOJO provides such annotations as:
> @Component
> @Provides // Provides a service
> public class Foo implements Service {
>     @Requires // Service dependency
>     private HelloService hello;
>
>
>     ...
> }
>
> You can find further info at
> http://felix.apache.org/site/how-to-use-ipojo-annotations.html
>
> About parameters, the iPOJO's way is to inject instance property. Those
> fields will be set before the execution of your constructor (between the
> super constructor invocation and the constructor code), and your constructor
> can use those fields, such as in:
>
> @Component
> @Provides // Provides a service
> public class Foo implements Service {
>
>     @Property
>     private String myString;
>
>     @Requires // Service dependency
>     private HelloService hello;
>
>     public Foo() {
>       // Can use myString here as well as hello
>     }
>     ...
> }
>
> Regards,
>
> Clement
>
>
> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>
>   
>> Hi,
>>
>> I would like to ask you about some way in Felix to export services in more
>> easy way only with annotation like in EJB3.x: @Stateful, @Stateless,
>> @Remote, @Local, @EJB, etc.
>> In my opinion the best way this to be done is inside of the OSGi framework.
>> Then all resources (services) can be exported to the framework just with
>> annotation. The same for needed services. What about if before to get some
>> service we have to pass some parameters to the constructor?
>>
>>
>> Regards,
>> Miro.
>>
>> ---------------------------------------------------------------------
>> 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


RE: Dependency Injection with annotations

Posted by Clement Escoffier <cl...@gmail.com>.
Hi,

I forget that I created those files :-). The maven plugin was renamed in 'maven-ipojo-plugin' to follow the Maven name.

Here is an updated version:
http://people.apache.org/~clement/ipojo/tutorials/annotations/annotation-tutorial.zip

It contains the examples and a preconfigured version of Felix. To compile them, just run the 'mvn clean package' command from the root of the folder where you unzip the archive. Then go in the Felix folder, and start it (java -jar bin/felix.jar). You can copy and paste command to run the example from the script.txt file (in the felix folder).

Clement

PS: I just updated the wiki page, just waiting for the next synchronization.

-----Original Message-----
From: Miroslav Nachev [mailto:m.nachev@prosyst.bg] 
Sent: jeudi 16 octobre 2008 15:29
To: users@felix.apache.org
Subject: Re: Dependency Injection with annotations

Hi,

Today I try to compile the examples on the web and I have the following 
error:
[ERROR]BUILD ERROR
------------------------------------------------------------------------
The plugin 'org.apache.felix:org.apache.felix.ipojo.plugin' does not 
exist or no valid version could be found

Probably the repository or/and the artifactId are changed?


Regards,
Miro.

http://felix.apache.org/site/how-to-use-ipojo-annotations.data/hello.impl.annotated-0.0.1-src.zip
http://felix.apache.org/site/how-to-use-ipojo-annotations.data/hello.client.annotation-0.0.1-src.zip


clement escoffier wrote:
> Hi,
>
> iPOJO provides such annotations as:
> @Component
> @Provides // Provides a service
> public class Foo implements Service {
>     @Requires // Service dependency
>     private HelloService hello;
>
>
>     ...
> }
>
> You can find further info at
> http://felix.apache.org/site/how-to-use-ipojo-annotations.html
>
> About parameters, the iPOJO's way is to inject instance property. Those
> fields will be set before the execution of your constructor (between the
> super constructor invocation and the constructor code), and your constructor
> can use those fields, such as in:
>
> @Component
> @Provides // Provides a service
> public class Foo implements Service {
>
>     @Property
>     private String myString;
>
>     @Requires // Service dependency
>     private HelloService hello;
>
>     public Foo() {
>       // Can use myString here as well as hello
>     }
>     ...
> }
>
> Regards,
>
> Clement
>
>
> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>
>   
>> Hi,
>>
>> I would like to ask you about some way in Felix to export services in more
>> easy way only with annotation like in EJB3.x: @Stateful, @Stateless,
>> @Remote, @Local, @EJB, etc.
>> In my opinion the best way this to be done is inside of the OSGi framework.
>> Then all resources (services) can be exported to the framework just with
>> annotation. The same for needed services. What about if before to get some
>> service we have to pass some parameters to the constructor?
>>
>>
>> Regards,
>> Miro.
>>
>> ---------------------------------------------------------------------
>> 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



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


Re: Dependency Injection with annotations

Posted by Miroslav Nachev <m....@prosyst.bg>.
Hi,

Today I try to compile the examples on the web and I have the following 
error:
[ERROR]BUILD ERROR
------------------------------------------------------------------------
The plugin 'org.apache.felix:org.apache.felix.ipojo.plugin' does not 
exist or no valid version could be found

Probably the repository or/and the artifactId are changed?


Regards,
Miro.

http://felix.apache.org/site/how-to-use-ipojo-annotations.data/hello.impl.annotated-0.0.1-src.zip
http://felix.apache.org/site/how-to-use-ipojo-annotations.data/hello.client.annotation-0.0.1-src.zip


clement escoffier wrote:
> Hi,
>
> iPOJO provides such annotations as:
> @Component
> @Provides // Provides a service
> public class Foo implements Service {
>     @Requires // Service dependency
>     private HelloService hello;
>
>
>     ...
> }
>
> You can find further info at
> http://felix.apache.org/site/how-to-use-ipojo-annotations.html
>
> About parameters, the iPOJO's way is to inject instance property. Those
> fields will be set before the execution of your constructor (between the
> super constructor invocation and the constructor code), and your constructor
> can use those fields, such as in:
>
> @Component
> @Provides // Provides a service
> public class Foo implements Service {
>
>     @Property
>     private String myString;
>
>     @Requires // Service dependency
>     private HelloService hello;
>
>     public Foo() {
>       // Can use myString here as well as hello
>     }
>     ...
> }
>
> Regards,
>
> Clement
>
>
> 2008/10/14 Miroslav Nachev <m....@prosyst.bg>
>
>   
>> Hi,
>>
>> I would like to ask you about some way in Felix to export services in more
>> easy way only with annotation like in EJB3.x: @Stateful, @Stateless,
>> @Remote, @Local, @EJB, etc.
>> In my opinion the best way this to be done is inside of the OSGi framework.
>> Then all resources (services) can be exported to the framework just with
>> annotation. The same for needed services. What about if before to get some
>> service we have to pass some parameters to the constructor?
>>
>>
>> Regards,
>> Miro.
>>
>> ---------------------------------------------------------------------
>> 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


Re: Dependency Injection with annotations

Posted by clement escoffier <cl...@gmail.com>.
Hi,

iPOJO provides such annotations as:
@Component
@Provides // Provides a service
public class Foo implements Service {
    @Requires // Service dependency
    private HelloService hello;


    ...
}

You can find further info at
http://felix.apache.org/site/how-to-use-ipojo-annotations.html

About parameters, the iPOJO's way is to inject instance property. Those
fields will be set before the execution of your constructor (between the
super constructor invocation and the constructor code), and your constructor
can use those fields, such as in:

@Component
@Provides // Provides a service
public class Foo implements Service {

    @Property
    private String myString;

    @Requires // Service dependency
    private HelloService hello;

    public Foo() {
      // Can use myString here as well as hello
    }
    ...
}

Regards,

Clement


2008/10/14 Miroslav Nachev <m....@prosyst.bg>

> Hi,
>
> I would like to ask you about some way in Felix to export services in more
> easy way only with annotation like in EJB3.x: @Stateful, @Stateless,
> @Remote, @Local, @EJB, etc.
> In my opinion the best way this to be done is inside of the OSGi framework.
> Then all resources (services) can be exported to the framework just with
> annotation. The same for needed services. What about if before to get some
> service we have to pass some parameters to the constructor?
>
>
> Regards,
> Miro.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>