Re: Eclipse 4 RCP - Tutorial -Dependency Injection

998 views
Skip to first unread message

Lars Vogel

unread,
Nov 5, 2012, 3:50:40 AM11/5/12
to vog...@googlegroups.com
This might help for the understanding: http://www.vogella.com/articles/EclipseRCP/article.html#extentcontext

The easiest way to place an object in the context is to define an OSGi service, see here for a tutorial: http://www.vogella.com/articles/OSGiServices/article.html

2012/10/23 utiDev <uti....@googlemail.com>
Hi,

i got stuck in the Eclipse 4 RCP - Tutorial at:

14. Dependency Injection and Annotations
14.1.  What is Dependency Injection?

There is a nice example how to inject a Logger or something else.

//  @Inject private Logger logger;
//  // DatabaseAccessClass would talk to the DB
//  @Inject private DatabaseAccessClass dao;

The one thing i don't get is where to register my classes i want to inject. Just creating a class and add the @Inject statement to another class seems not to be enough.

How to register my class so the applicationcontext is able to inject it?

I created a sample application. I created a class A with a function sayHello() :). What to do to be able to inject it to one of my handlers?

Thanks in advance :)

--
You received this message because you are subscribed to the Google Groups "vogella" group.
To view this discussion on the web visit https://groups.google.com/d/msg/vogella/-/-2vtyR5DRmUJ.
To post to this group, send email to vog...@googlegroups.com.
To unsubscribe from this group, send email to vogella+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/vogella?hl=en.


Lars Vogel

unread,
Nov 11, 2012, 6:20:30 PM11/11/12
to vog...@googlegroups.com
Hello,


Best regards, Lars

2012/11/11 roschulze <rosch...@googlemail.com>
Hi,

I have a similar problem.
I have created my own service as plugin to use him in my application with dependency injection. This works fine inside classes like handlers.
But if I inject my service in any usual class (which is responsible for logic or sth. else) it does not work. The injected service is everytime null.
I also tried to inject some of the standard service like logger and eventbroker. I have determined the same behavior. It works in handler but not in my own classes.

Do I have to consider something else?

Thanks a lot.
To view this discussion on the web visit https://groups.google.com/d/msg/vogella/-/wgZ0SJpGh0oJ.

Lars Vogel

unread,
Jun 5, 2013, 5:29:11 AM6/5/13
to vog...@googlegroups.com
I think creating an OSGi service with DS is really simple but this is of course a question of perception


2013/5/28 uti delev <uti....@googlemail.com>
Hi,

thank you, i'll try, but it feels a little over sized to create and install an additional service just to install a single handler? Or am i missing something?

Thanks, Dennis
To unsubscribe from this group and stop receiving emails from it, send an email to vogella+u...@googlegroups.com.

To post to this group, send email to vog...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages