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

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