Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » DI and own Objects (EMF)
DI and own Objects (EMF) [message #743275] Fri, 21 October 2011 05:48 Go to next message
Sir Wayne is currently offline Sir Wayne
Messages: 206
Registered: July 2009
Senior Member
Hello,

i want to inject a own Object (EMF Factory) in my part.

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext bundleContext) throws Exception {
		Activator.context = bundleContext;
		 // Get Bundle Information
		  Bundle bundle = FrameworkUtil.getBundle(getClass());
		  IEclipseContext eclipseCtx =   
		      EclipseContextFactory.getServiceContext(bundleContext);

		 
		  eclipseCtx.set(MyFactory.class, MyFactory.eINSTANCE);
		
	}


public class DetailPart {
	@Inject
	private MyFactory myFactory;


But it doesn't work

org.eclipse.e4.core.di.InjectionException: Unable to process "DetailPart.myFactory": no actual value was found for the argument "MyFactory".

Is the context wrong?
Re: DI and own Objects (EMF) [message #743308 is a reply to message #743275] Fri, 21 October 2011 06:36 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5230
Registered: July 2009
Senior Member
Hi,

The root-context used by the framework to create the part instances is
totally different to the root context you are create in your activator!

2 possibilities:

a) you contribute the factory through Addons the addon gets the correct
IEclipseContext

b) you use a ContextFunction

Tom

Am 21.10.11 11:48, schrieb SirWayne:
> Hello,
>
> i want to inject a own Object (EMF Factory) in my part.
>
>
> /*
> * (non-Javadoc)
> * @see
> org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
> */
> public void start(BundleContext bundleContext) throws Exception {
> Activator.context = bundleContext;
> // Get Bundle Information
> Bundle bundle = FrameworkUtil.getBundle(getClass());
> IEclipseContext eclipseCtx =
> EclipseContextFactory.getServiceContext(bundleContext);
>
> eclipseCtx.set(MyFactory.class, MyFactory.eINSTANCE);
>
> }
>
>
>
> public class DetailPart {
> @Inject
> private MyFactory myFactory;
>
>
> But it doesn't work
>
> org.eclipse.e4.core.di.InjectionException: Unable to process
> "DetailPart.myFactory": no actual value was found for the argument
> "MyFactory".
>
> Is the context wrong?
Re: DI and own Objects (EMF) [message #743353 is a reply to message #743308] Fri, 21 October 2011 07:31 Go to previous message
Sir Wayne is currently offline Sir Wayne
Messages: 206
Registered: July 2009
Senior Member
Thanks Tom, the AddOn is a nice solution and it works perfectly =).
Previous Topic:Double invocation of a Login Dialog using LifeCyleHandler
Next Topic:Controls
Goto Forum:
  


Current Time: Thu Jul 24 00:43:32 EDT 2014

Powered by FUDForum. Page generated in 0.01619 seconds