Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 317664 - Support InjectService-Annotation on member variables
Summary: Support InjectService-Annotation on member variables
Status: RESOLVED WONTFIX
Alias: None
Product: Riena
Classification: RT
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-23 04:33 EDT by Steffen Kriese CLA
Modified: 2010-07-18 17:49 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steffen Kriese CLA 2010-06-23 04:33:55 EDT
In an typical riena-application OSGI-Services don't get unbound while the application is running, so why do have to write a bind and unbind method for every service?

At the moment we have to inject a service like this:

private IMyService myService;
	
@InjectService
public void bind(IMyService service) {
	this.myService = service;
}

public void unbind(IMyService service) {
	this.myService = null;
}


I would prefer to declare the InjectService-Annotation on the member variable itself and get rid of the boilerplate code:

@InjectService 
private IMyService myService;
Comment 1 Stefan Liebig CLA 2010-06-24 10:12:27 EDT
Just my 2 € cents:

Even if we assume that an unbind() is very unlikely to be called in ´typical´ rcp application I wonder how this:

@InjectService 
private IMyService myService;

can handle injection of multiple services (same interface).
Additionally encapsulating the access with bind/unbind allows to perform special actions in case a service arrives or goes away.
Comment 2 Christian Campo CLA 2010-06-24 10:26:13 EDT
I think the way to go is to use the JSR 330 that e4 is using to live and die with all the limitation and capibilities they have.

My 2 cent on member injection versus method injection is that you probably could use both in different usecases. I would like to keep bind and unbind and there are (as Stefan pointed out) a number of disadvantages of using member variable injection.

- you get no event on bind and unbind
- no injection of multiple services

So on member variable injection you would assume that always require the attribute service ranking to make sense. (or use that as default)
Comment 3 Steffen Kriese CLA 2010-06-25 02:05:30 EDT
Don't get me wrong. The member injection should just be an option, not the only choice.

+1 on JSR 330 support in Riena!
Comment 4 Christian Campo CLA 2010-07-18 17:49:56 EDT
sooner or later we are going to switch to JSR-330 whch allows this already. I see no advantage to extend our own injection mechanism.