Bug 430190 - [DI] The 'appendToContext' parameter for the Creatable annotation
Summary: [DI] The 'appendToContext' parameter for the Creatable annotation
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Runtime (show other bugs)
Version: 4.4   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: 2014-03-12 10:23 EDT by Daniel Rolka CLA
Modified: 2017-01-15 06:29 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Rolka CLA 2014-03-12 10:23:25 EDT
I think it would be useful to add the 'appendToContext' parameter for the Creatable annotation and put the new instance of the 'Creatable' object to the current IEclipseContext instance, when the parameter is set to true. When the class is annotated with the Singleton it should be the main application context
Comment 1 Paul Webster CLA 2014-03-12 10:36:14 EDT
I'm not really a big fan of Creatable to begin with, as we can't tell if something has been instantiated for a specific object instance injection or provided by the context.

So now that you'd like the option to stash a Creatable in a context, I have to ask why?  What specific usecase are you trying to solve?  How often does this come up?

We usually seek fine grained control over where our objects are instantiated.

PW
Comment 2 Daniel Rolka CLA 2014-03-12 10:52:38 EDT
(In reply to Paul Webster from comment #1)
> I'm not really a big fan of Creatable to begin with, as we can't tell if
> something has been instantiated for a specific object instance injection or
> provided by the context.
> 
> So now that you'd like the option to stash a Creatable in a context, I have
> to ask why?  What specific usecase are you trying to solve?  How often does
> this come up?
> 
> We usually seek fine grained control over where our objects are instantiated.
> 
> PW

It is some kind of shortcut for user. Having the class annotated with @Creatable(appendToContext=true) they can directly retrieve such instance from the context without performing additional context registration steps. From my point of view it simplifies the source code.

Daniel
Comment 3 Paul Webster CLA 2014-03-12 10:58:48 EDT
(In reply to Daniel Rolka from comment #2)
> 
> It is some kind of shortcut for user. Having the class annotated with
> @Creatable(appendToContext=true) they can directly retrieve such instance
> from the context without performing additional context registration steps.
> From my point of view it simplifies the source code.

I'm looking for a couple of specific instances where this will be used.  Right now, I don't think we use it in the platform at all, and because we want to control where items are created, we don't have a lot of opportunities.

PW
Comment 4 Guido Schnepp CLA 2017-01-15 02:39:01 EST
There's another reason why the ability to add new objects to a specific context is necessary, the @Singleton annotation. Tom Schindl has written about it in 2009 already: https://www.eclipse.org/forums/index.php/t/797114/

For me, I'm hit by the same problem described in the forum thread, that my @Singleton is destroyed at undesired time. Since my problem is more specific, it could also help me to just let singletons be added to the root context automatically instead of the most current context.

Guido
Comment 5 Guido Schnepp CLA 2017-01-15 02:50:52 EST
(In reply to Guido Schnepp from comment #4)
> There's another reason why the ability to add new objects to a specific
> context is necessary, the @Singleton annotation. Tom Schindl has written
> about it in 2009 already: https://www.eclipse.org/forums/index.php/t/797114/
> 
> For me, I'm hit by the same problem described in the forum thread, that my
> @Singleton is destroyed at undesired time. Since my problem is more
> specific, it could also help me to just let singletons be added to the root
> context automatically instead of the most current context.
> 
> Guido

Correction: Toms answer is from 2014, not 2009 (his registration date :-))
Comment 6 Dirk Fauth CLA 2017-01-15 06:29:28 EST
First question, is it still the case that a @Singleton value is not added to the application/root context? IMHO that would be a natural assumption. 

And additionally if you need more control in which context an object is located you should use an IContextFunction. 

I'm against adding an additional parameter to an annotation that is not recommended nowadays.