title: Multiple references and dependencies with declarative services
body: <p>I am experiencing problems with the order components are loaded when using OSGi declaratives services through Karaf.</p>
  
  <p>I have this situation:</p>
  
  <pre><code>@Component
  public class A implements IA
  {
    doSomething() {...}
  }
  
  
  @Component
  public class B implements IB
  {}
  
  @Component
  public class C implements IC
  {
    @Reference 
    IA a
  
    @Reference 
    (cardinality = ReferenceCardinality.MULTIPLE,
     policyOption = ReferencePolicyOption.GREEDY,
     unbind = "doUnRegister" )
    void doRegister(IB b)
    {
      a.doSomething()
    }
  
    void doUnregister(IB b)
    {
      ...
    }
  }
  </code></pre>
  
  <p>A, B, and C are three distinct bundles.</p>
  
  <p>When firing up Karaf, a B is registered and doRegister is called. However: service A is not ready (a is null).</p>
  
  <p>I tried the following:</p>
  
  <ol>
  <li>set the start level of A to something lower than B... Did not work</li>
  <li>to pickup the registrations of B in a work-list and actually use A later when C was activated. Did not work AND the code was cluttered.</li>
  <li>searched for a way to write this requirement through the annotation on doRegister - NOT possible.  </li>
  <li>I tried to use a service locator and get the context through an activate method on C - DID NOT WORK, it crashed Karaf.</li>
  </ol>
  
  <p>I must clearly be missing something, is there anybody that have experienced similar problems and found a solution?</p>
  
  <p><strong>UPDATE:</strong> 
  Reference A a changed into IA a. Added forgotten information on Reference B().</p>