Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] Question about DI/ DS and Application model

I agree that for this particular example where only one service is acquired the usage of DS is probably overkill. However if several services had been needed, I think it would have probably been better to use DS over writing all the service handling manually.
As for the relevance of the example, I would argue that it is very relevant as this is probably the simplest thing that one can do: write a little piece of code that uses services to perform a task and then maybe make it available as a application (or an action, or...). It does not need nor want to publish a service.

At this point the two root causes seem to be:
- The only way for DS to provide the objects resulting from the injection is through services and this is cumbersome and ends up polluting the service space.
- Bridging the service and extension world so that created extensions can get things injected to them.

I looked at the code in the solution3 package and if I understand it correctly, it seems to be an implementation of 1.2 since the RepositoryDumper is registered by DS and then acquired by the application itself.

PaScaL

Inactive hide details for John Arthorne---09/16/2009 09:58:08 PM---Eventually someone has to decide which implementation of IMeJohn Arthorne---09/16/2009 09:58:08 PM---Eventually someone has to decide which implementation of IMetadataRepositoryManager is going to be used. I think in the case of


From:

John Arthorne/Ottawa/IBM@IBMCA

To:

Equinox development mailing list <equinox-dev@xxxxxxxxxxx>

Date:

09/16/2009 09:58 PM

Subject:

Re: [equinox-dev] Question about DI/ DS and Application model





Eventually someone has to decide which implementation of IMetadataRepositoryManager is going to be used. I think in the case of an application it is quite reasonable for the application to make this decision directly (by looking up the service, perhaps with some filter that helps to select the manager to use). By moving the lookup of IMetadataRepositoryManager into a DS component it just hides the fact that it is a simple service lookup and doesn't seem to offer any advantage.

I think because both the service declaration, the implementation, and the client are all in the same bundle it's not a particularly interesting case. However I could imagine in more complex cases something like your solution 3 would be interesting. An executable extension factory could allow the services required by an executable extension to be injected into it rather than having the extension reach out.

You'll see another package "solution3" in the bundle where I was playing around with another approach. I'm not sure it's any better than your solution 1 but you can take a look.

John


Pascal Rapicault/Ottawa/IBM@IBMCA
Sent by: equinox-dev-bounces@xxxxxxxxxxx

09/16/2009 04:00 PM

Please respond to
Equinox development mailing list <equinox-dev@xxxxxxxxxxx>
To
Equinox development mailing list <equinox-dev@xxxxxxxxxxx>
cc
Subject
[equinox-dev] Question about DI/ DS and Application model




Today I have done some more DI exploration using DS to see how it fits with the constructs we have in eclipse and I'm struggling to integrate in a nice way with the application model (I mean without using static) and I'm looking to know how others are doing this?
The one line summary of my experiment is: I have a class that does some work (named RepositoryDumper), it needs a service (RepoMgr). I want now to create an eclipse application that invokes the RepositoryDumper and I would like to not have to acquire the RepoMgr service manually.

Here is what I have been exploring with:
Solution 1:
I have an application declared in the plugin.xml. I have created a DS component that instantiates RepositoryDumper. However the question now is how does the application (remember that an eclipse application extension needs to provides n class) can get a hold of the RepositoryDumper instance that got created by DS:
- 1.1: Ugly -> Store the instance RepositoryDumper in the Activator of the plug-in
- 1.2: Get the RepositoryDumper be registered as a Service and have the application get this service. I don't like this because now RepositoryDumper is visible to everybody just so I can get access to it

Solution 2:
This solution assumes that the declarative approach to the eclipse application model is the hindrance and works around it by registering an ApplicationDescriptor (org.osgi.service.application). To do so I create a DS component that instantiates the RepositoryDumper and also register an ApplicationDescriptor as a service. This has the nice attribute that everything gets injected and that the application is only available to run if all the necessary pieces are available. However it requires a lot of code since one has to implement ApplicationDescriptor and ApplicationHandle, and I don't think this application would even be launchable using the -application argument.

Solution 3:
This solution is an hybrid between 1 and 2 using the IExecutableExtensionFactory.
There is a DS component that creates the RepositoryDumper and register a service, let's call it X. Then let's make the class specified in application extension (in the plugin.xml) implements IExecutableExtensionFactory and have it get the service X. This solution allows to have the application construction be completely done by injection however given that the application is contributed through extension registry it still is visible even though not ready to run.

How are others doing this? Is this a real problem or is it just me? Should I just not worry about that and use static fields?
Btw, the code is available /cvsroot/rt org.eclipse.equinox/incubator/p2/bundles/org.eclipse.equinox.p2.diagnostic Only solution 1 and 2 are available.

Thx for your attention and feedback

PaScaL
_______________________________________________
equinox-dev mailing list
equinox-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/equinox-dev
_______________________________________________
equinox-dev mailing list
equinox-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/equinox-dev


GIF image

GIF image


Back to the top