Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Creation of IEclipseContext
Creation of IEclipseContext [message #986882] Thu, 22 November 2012 09:09 Go to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Hi,

I have read that it is supported and preferred to create your own IEclipseContext to avoid context variable collisions.

We are thinking of adding DI to NatTable in some kind of way. We are still working on the architecture, so I don't want to start the discussion on how and why here. I just want to gather some information to find the "best" solution.

As NatTable is a complex framework, I thought of creating an IEclipseContext for every NatTable instance itself to avoid variable collisions if you use more than one NatTable in a part.

So there are currently two questions on that:

1. Which is the preferred way to create a new IEclipseContext and add it to the context hierarchy?

I have seen two ways doing this:
public IEclipseContext createContext(IEclipseContext parentContext) {
	//Option 1: create by factory and set parent
	IEclipseContext context1 = EclipseContextFactory.create();
	context1.setParent(parentContext);
		
	//Option 2: create child of parent
	IEclipseContext context2 = parentContext.createChild();

	...
}

Is there any advantage for one of them?

2. How to tell the classes in NatTable that they should use / are connected to our created context? Do we have to add something there or is this handled by the Eclipse platform itself?

Thanks for your help in advance,
Dirk
Re: Creation of IEclipseContext [message #986921 is a reply to message #986882] Thu, 22 November 2012 11:21 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Am 22.11.12 10:09, schrieb Dirk Fauth:
> Hi,
>
> I have read that it is supported and preferred to create your own
> IEclipseContext to avoid context variable collisions.
>
> We are thinking of adding DI to NatTable in some kind of way. We are
> still working on the architecture, so I don't want to start the
> discussion on how and why here. I just want to gather some information
> to find the "best" solution.
>
> As NatTable is a complex framework, I thought of creating an
> IEclipseContext for every NatTable instance itself to avoid variable
> collisions if you use more than one NatTable in a part.
>
> So there are currently two questions on that:
>
> 1. Which is the preferred way to create a new IEclipseContext and add it
> to the context hierarchy?
>
> I have seen two ways doing this:
>
> public IEclipseContext createContext(IEclipseContext parentContext) {
> //Option 1: create by factory and set parent
> IEclipseContext context1 = EclipseContextFactory.create();
> context1.setParent(parentContext);
>
> //Option 2: create child of parent
> IEclipseContext context2 = parentContext.createChild();
>
> ...
> }
>
> Is there any advantage for one of them?

Option 2 is better - you should also give your context a name so this
helps with debugging!

>
> 2. How to tell the classes in NatTable that they should use / are
> connected to our created context? Do we have to add something there or
> is this handled by the Eclipse platform itself?
>

Classes who are created through ContextInjectionFactory.create are by
default registered with the given context and are informed when the
context is diposed if the have an @PreDestroy method.

If the object is created by hand you can push it into the
IEclipseContext by calling CIF.invoke.

Tom
Re: Creation of IEclipseContext [message #986924 is a reply to message #986921] Thu, 22 November 2012 11:37 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Thanks for the quick reply Tom. Yesterday I told my colleagues about ContextInjectionFactory and how it should be used, today I'm asking the same question I answered yesterday. Need holidays!

I guess you mean ContextInjectionFactory.make instead of ContextInjectionFactory.create?

[Updated on: Thu, 22 November 2012 11:49]

Report message to a moderator

Previous Topic:Difference between org. .. .observable and org. .. .observable.source
Next Topic:org.eclipse.ui 4 0.jar download
Goto Forum:
  


Current Time: Fri Mar 29 00:39:20 GMT 2024

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

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

Back to the top