Skip to main content


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 09:48 Go to next message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 244
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 10:36 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
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 11:31 Go to previous message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 244
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 Apr 18 13:46:07 GMT 2024

Powered by FUDForum. Page generated in 0.02047 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top