[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.rt.riena] Re: Problem with annotated injection

Stefan Liebig schrieb:
Rüdiger Rensinghoff-Kranen wrote:
Stefan Liebig schrieb:
Rüdiger Rensinghoff-Kranen wrote:
Stefan Liebig schrieb:
Hi Rüdiger,

When using annotations for injection something has to interpret those annotations and perform the necessary actions.
In the case where classes are defined within extension points like your SubModuleController the ExtensionInjector takes care of the wiring.
I you create a pojo yourself you have the choice of using either:
-Inject.Service().into( pojo ). ..
or
- use annotations and do a Wire.instance( pojo ).andStart()


HTH
Stefan

Rüdiger Rensinghoff-Kranen wrote:
Hello,


in Riena I like to inject services with @InjectService. Everything is easy in a SubModuleController class. But in pojo's I have the problem, that bind won't be called.


The following code runs well from Activator.start for pojo CurrentUser without annotation:

currentUser = new CurrentUser();
Inject.service(ISubjectHolderService.class.getName())
.into(currentUser)
.bind("bindSubjectHolderService")
.unbind("unbindSubjectHolderService")
.andStart(context);
Inject.service(IUserService.class.getName())
.into(currentUser)
.bind("bindUserService")
.unbind("unbindUserService")
.andStart(context); If in Activator.start or any other place only
currentUser = new CurrentUser()
is called and CurrentUser is annotated like this the services are null.



public class CurrentUser {
private ISubjectHolderService subjectHolderService;
private IUserService userService;
@InjectService(service= IUserService.class ,unbind = "unbindUserService")
public void bindUserService(IUserService srv) {
this.userService = srv;
}
@InjectService(service=ISubjectHolderService.class,unbind="unbindSubjectHolderService")


public void bindSubjectHolderService(ISubjectHolderService srv) {
this.subjectHolderService = srv;
}



If tried to change @InjectService or use @WireWith but I can't get it run.


What goes wrong.

Rüdiger




Hello Stefan,


thanks for your rapide response. I tried Wire.instance and it works well and is more convenient to me.



Rüdiger


Hello Rüdiger,

You can even simplify your pojo annotations:

public class CurrentUser {
    private ISubjectHolderService subjectHolderService;
    private IUserService userService;
    @InjectService()
    public void bindUserService(IUserService srv) {
        this.userService = srv;
    }
    @InjectService()
    public void bindSubjectHolderService(ISubjectHolderService srv) {
        this.subjectHolderService = srv;
    }

   ..

}

The service class is now taken from the parameter type of the annotated bind method and the unbind method name is generated by prefixing the annotated bind method with with "un".

Tschüß,
Stefan

Hello Stefan,

thanks very much for your helpfull usage hint. It would be great to find such information in a description for Riena. Now I have to learn it the hard way. Spend hours, that I not really have, by try and error and greping in inner classes of the framework. But Riena is worth it. Thanks to the team.


Rüdiger




Hello Rüdiger,

You are right http://wiki.eclipse.org/Riena_Getting_Started_with_Wiring needs some polishing. Thanks for the hint!
Keep posting your questions and comments! We will try hard.


Tschüß,
Stefan
Hi Rüdiger,

I know you said you had no time but still wanted our documentation in Riena to be better. Help us to help us and write a little paragraph in the wiki page that Stefan mentioned and add the things you were missing. Add a little documentation, which I guess you can copy in parts from this thread to help others to be faster in understanding the concepts....

thanks
christian