Community
Participate
Working Groups
The common pattern for use contexts with UI is: - get a parent context - create a local context parented of the parent context - add some one-time use values in the local context - #make() an object using the local context The problem comes at the end of the life cycle: the local context is not stored and therefore we can't use #uninject(object, localContext). Possible solutions: 1) Add a variable to the object: @Inject IEclipseContext localContext; and use it to dispose the local context, severing links between the parent context, local context, and the object Pros: can be done with no changes to the framework Cons: a new field has to be added to every affected class 2) Keep a map of all contexts injected into the object and add a method static #getInjectedContext() which would return the local context used in #make() and can be used to uninject Cons: memory and performance impact - having a table and that lists all contexts and all injected objects and having to search through them on every context disposal scares me. 3) Create a new #make() / #inject() method that would take two contexts: dynamic and static, the parent context being used as dynamic and local context used as static. localContext = EclipseContextFactory.create(); object = ContextInjectionFactory.make(parentContext, localContext); and then call #uninject(object, parentContext) as there will be no ties established to the local context. Cons: it is RC1 and this will be a substantial change. ---- I'll try (3) to see the impact of changes and if that turns out to be too much at this point, I'll do (2) for the initial release.
Created attachment 172458 [details] Patch + Added: ContextInjectionFactory#make(clazz, IEclipseContext context, IEclipseContext staticContext) - values from the staticContext override values from the context - changes to values injected from the staticContext are not tracked - disposal or GC of the staticContext does not affect injected object - the context is considered to be injected into the object, uninject / disposal will of the context will affect the object + Changed #uninject() to call @PreDestroy + For completness, added similar invokation method: ContextInjectionFactory#invoke(object, qualifier, context, localContext, defaultValue) ===== How to use: IEclipseContext localContext = EclipseContextFactory.create(); localContext.set("abc", "myValue"); object = ContextInjectionFactory.make(class, context, localContext); This allows passing extra non-tracked values that are not present in the "real" context.
Patch appled to CVS Head.
Created attachment 172794 [details] Patch to IContributionFactory One more change: make the new functionality available in the IContributionFactory.
Patch "Patch to IContributionFactory" applied to CVS Head. The patch makes new method vissible via IContributionFactory.
Created attachment 172996 [details] Patch to place the 'uninvoke' behavior into the PRE To test this just start an inner with a new WS, minimize a stack an right-click on the perspective in the switcher and choose 'reset'.
Re-opening...
Created attachment 173006 [details] Patch for the CCE
Patch applied to CVS Head.