Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » OSGI DS vs DI via Contexts(When to use what?)
OSGI DS vs DI via Contexts [message #1013434] Sat, 23 February 2013 16:43 Go to next message
Marina Knieling is currently offline Marina KnielingFriend
Messages: 83
Registered: February 2013
Member
Hi @ all,

I'm working on an e4 RCP/OSGI application for my bachelor project.

I finally managed to get an OSGI DS working and injected in my application and it works fine.

I have a general question about the DS and DI via those (eclipse) contexts.
I know that DI with DS works fine, but I think you should use a DS (or a service in general) only when you need that functionality in the whole application (e.g. database access).

If I just wanted to open a wizard or FileDialog from my main menu, I think there is no need to inject it via a service, isn't it? I presume I could do this differently (DI via contexts?).

I have a bundle that only includes the ApplicationModel with all those Commands, Handlers, Menus, etc. I need to open a wizard from a handler.

What I've done so far is:

Create a DS in a UI Bundle that creates the Wizard and opens it. My service interface therefore has the two methods createWizard(type) and open(). The implementation is kind of a factory that creates the real wizard depending on the type parameter and the open method wraps the Wizard in the WizardDialog and opens it.
So in my Handler class I inject the WizardService, create the Wizard I want and open it. So I don't have any dependencies on the jface WizardDialog class in that handler.

Do you think this is a good way of doing it or should I rather try and get the wizard injected by the context as I need it only in that handler? I don't know how this actually works. I think I somehow need to add my object/class to some context.

Please share any thoughts about my approach with me. I know that it works with the DS, but I don't want to "overuse" DS for things that would work with "normal" DI.

So in general the question is: when do I use which approach?

Thanks,
Marina
Re: OSGI DS vs DI via Contexts [message #1014218 is a reply to message #1013434] Mon, 25 February 2013 11:43 Go to previous message
Kirill Zotkin is currently offline Kirill ZotkinFriend
Messages: 21
Registered: July 2009
Junior Member
Quote:
you should use a DS (or a service in general) only when you need that functionality in the whole application (e.g. database access).

If I just wanted to open a wizard or FileDialog from my main menu, I think there is no need to inject it via a service, isn't it?

Yes, you can inject the selection to handler.

Quote:
I have a bundle that only includes the ApplicationModel with all those Commands, Handlers, Menus, etc.

If it is done so, I also suggest to have a Wizard class in this bundle.

Quote:
So in my Handler class I inject the WizardService, create the Wizard I want and open it. So I don't have any dependencies on the jface WizardDialog class in that handler.

Well, what is the necessity of separating the JFace from handler's bundle at all? It might come handy in some non-default scenario, but complexity has costs that should be covered.

Quote:
Do you think this is a good way of doing it...

It is a more complex way. It's profitability is determined by the requirements.

Quote:
...should I rather try and get the wizard injected by the context as I need it only in that handler?

You can inject the Wizard object to handler in case, for example, you have many different wizards.

Quote:
I think I somehow need to add my object/class to some context.

You can do this by IEclipseContext.set(Class or String, Object).


Quote:
Please share any thoughts about my approach with me. I know that it works with the DS, but I don't want to "overuse" DS for things that would work with "normal" DI.

When you can use DI, why use DS?


Quote:
So in general the question is: when do I use which approach?

Di: for consuming services, for dependencies in UI and somewhere else, in program created with the same approach as eclipse.
When don't have access to DI, at lower level - services.

[Updated on: Mon, 25 February 2013 20:11]

Report message to a moderator

Previous Topic:Dynamic menu with MHandledMenuItem
Next Topic:e4 and xtend editors
Goto Forum:
  


Current Time: Tue Mar 19 11:51:45 GMT 2024

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

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

Back to the top