Bug 409272 - Add dependency injection support for @PostConstruct annotated methods in new message extension
Summary: Add dependency injection support for @PostConstruct annotated methods in new ...
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Runtime (show other bugs)
Version: 4.5   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: platform-runtime-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-28 08:18 EDT by Dirk Fauth CLA
Modified: 2014-09-22 05:23 EDT (History)
1 user (show)

See Also:


Attachments
Add DI support in @PostConstruct (9.82 KB, patch)
2013-05-28 08:18 EDT, Dirk Fauth CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Fauth CLA 2013-05-28 08:18:42 EDT
Created attachment 231611 [details]
Add DI support in @PostConstruct

The new message extension in tools.services supports evaluation and execution of a method annotated with @PostConstruct to support similiar functionality as the static init block for OSGi NLS messages. Unfortunately it doesn't support dependency injection, which is supported in other places in the Eclipse application platform.

This is described here: http://www.vogella.com/blog/2013/05/22/eclipse-internationalization-part-24-new-message-extension-by-dirk-fauth-and-tom-schindl/

The main reason for this is the knowledge of the context to use for injection. It also could break the caching mechanism if not done right.

I already modified the code to also support dependency injection for @PostConstruct annotated methods based on the context of the requestor. 

Still open is:

- configuration of the context to use for injection

Usually the application context should be used (or the OSGi context if the application context is not available), as in this case the caching mechanism is working correctly as it is. But you could also configure e.g. the context of the MPerspective so for each perspective you could have your own messages object initialized. In this case the caching needs to be extended for the knowledge of the context.

- determine and using the configured context instead of always using the context of the requestor
Comment 1 Dirk Fauth CLA 2014-09-22 05:06:57 EDT
As the new message extension was moved to the platform, this ticket also needs to be reassigned.

Note that the attached patch was created as the new message extension was part of the e4 tools. Therefore it is not quite valid.

Since the patch is also not complete and needs some modifications and discussions, it will be updated in the future with a Gerrit patch.
Comment 2 Thomas Schindl CLA 2014-09-22 05:16:56 EDT
What I'm worried about with DI is that how it plays with the cache let's assume we request Messages the first time on the Window-Context and afterwards on the Part-Context - the @PostConstruct was called on the IEclipseContext of the window the only solution I can think of and which needs to be documented is that @PostConstruct is done on the MApplication context or even OSGi-Context?
Comment 3 Dirk Fauth CLA 2014-09-22 05:23:31 EDT
Good point. But doesn't ReferenceType.NONE mean that every requestor gets its own Messages instance? So Window and Part would have different instances?