Hi

I want to make use of the dependendy injection feature of hivemind. My
application needs to have two services:

  public interface ServiceInterface1 {...
  
  public interface ServiceInterface2 {...

that are both implemented in one service implementation class:

  public class ServiceImpl implements ServiceInterface1, ServiceInterface2
{...

My hivemind.xml looks like this:

  <service-point id="service1" interface="ServiceInterface1"/>
  <service-point id="service2" interface="ServiceInterface1"/>
  
  <implementation service-id="service1">
    <invoke-factory model="singleton">
      <construct class="ServiceImpl"/>
    </invoke-factory>
  </implementation>
  <implementation service-id="service2">
    <invoke-factory model="singleton">
      <construct class="ServiceImpl"/>
    </invoke-factory>
  </implementation>

The class that wants to make use of the service has the following
constructor:

  public class ServiceConsumer {
    private ServiceInterface1 service1;
    private ServiceInterface2 service2;
    
    public ServiceConsumer(ServiceInterface1 service1, ServiceInterface2
service2) {
        this.service1 = service1;
        this.service2 = service2;
        ...
        
That looks strange for the first moment, but I need that for design purpose.
My expectation is, that both parameters ('service1' and 'service2') that are
injected into the constructor are the same instances of 'ServiceImpl',
because this is defined as singleton. But it is not! I get 2 different
'ServiceImpl' instances... in my opinion that should be impossible for a
singleton implementation!

Did I miss something? Do you have a solution?

Thanks for any help.
Regards
Christoph.

By the way, changing the 'model' attribute to 'primitive' does not fix the
problem!
-- 
View this message in context: 
http://www.nabble.com/Singleton-is-no-singleton%21--tf2560168.html#a7134820
Sent from the Hivemind - User mailing list archive at Nabble.com.

Reply via email to