Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » declarative services dependency injection questions
declarative services dependency injection questions [message #104106] Sun, 20 January 2008 12:05
David Donohue is currently offline David Donohue
Messages: 104
Registered: July 2009
Senior Member
Hello,
I am having a perplexing problem, that DS is not working as I expected.

I have a bundle org.bundleA, which declares both a service and a component.

<?xml version="1.0"?>
<component name="ComponentA" immediate="true">
<implementation class="org.my.ComponentA"/>
<service>
<provide interface="org.my.IComponent"/>
</service>
</component>

<?xml version="1.0"?>
<component name="ServiceA" immediate="true">
<implementation class="org.my.ServiceA"/>
<reference name="IComponent"
interface="org.my.IComponent"
bind="addComponent"
cardinality="1..n"
policy="dynamic" />
</component>

I test this in the bundle's Activator.

public void start(BundleContext context) throws Exception {
ServiceA serviceA = new ServiceA();
System.out.println("Created ServiceA with " + serviceA.countComponents() + " components");
}

and I get this output
Created ServiceA with 0 components
Running ServiceA.addComponent()

So my first question is: is this the order in which this should happen? Note that the componets do not seem to be available until later (too late).

So I move the above start method to a 2nd bundle's Activator instead. And here is the output

Created ServiceA with 0 components

Apparently the DS did not kick in and inject the dependencies when I create a ServiceA object from a 2nd bundle.

Second question: Is this the expected behavior? Can only the bundle which declares the component and/or service use them?

Thanks!
David
Previous Topic:System Resources Monitoring
Next Topic:Activator invalid problem
Goto Forum:
  


Current Time: Sun Oct 26 00:22:34 GMT 2014

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

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