Bug 317595 Add ability to uninject without specific context
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.
bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ReflectionContributionFactory.java
if (uri.segmentCount() > 3) {
			String prefix = uri.segment(2);
			IContributionFactorySpi factory = (IContributionFactorySpi) languages.get(prefix);
			StringBuffer resource = new StringBuffer(uri.segment(3));
			for (int i = 4; i < uri.segmentCount(); i++) {
				resource.append('/');
				resource.append(uri.segment(i));
			}
			contribution = factory.create(bundle, resource.toString(), context);
		} else {
			String clazz = uri.segment(2);
			try {
				Class<?> targetClass = bundle.loadClass(clazz);
				contribution = ContextInjectionFactory.make(targetClass, context);
				if (contribution == null) {
					String message = "Unable to load class '" + clazz + "' from bundle '" 
							+ bundle.getBundleId() + "'"; 
					Activator.log(LogService.LOG_ERROR, message, new Exception());
				}
			} catch (ClassNotFoundException e) {
				contribution = null;
				String message = "Unable to load class '" + clazz + "' from bundle '" 
						+ bundle.getBundleId() + "'"; 
				Activator.log(LogService.LOG_ERROR, message, e);
			} catch (InjectionException e) {
				contribution = null;
				String message = "Unable to create class '" + clazz + "' from bundle '" 
						+ bundle.getBundleId() + "'"; 
				Activator.log(LogService.LOG_ERROR, message, e);
			}