Anatoly
Anatoly

Reputation: 89

Register same class under multiple interfaces in PicoContainer

I have next input:

  1. PicoContainer instance configured next way:
MutablePicoContainer pico = new PicoBuilder()
                .withLifecycle()
                .withCaching()
                .withConstructorInjection()
                .withSetterInjection()
                .withHiddenImplementations()
                .build();

The important thing that it uses hidden implementations.

  1. The classes, let's say, structure:
    interface A {

    }

    interface B {

    }

    public class AB implements A, B {
        public AB(/*dependencies on other components that exist in container*/) {

        }
    }
  1. The problem:

I want to register same class instance in the context under those interfaces described before, something like this:

pico.addComponent(A.class, AB.class);
pico.addComponent(B.class, pico.getComponent(A.class)); // cuses ClassCastException since proxy wrapper is used

The main idea is to initialize class instance usig existing context and do this only once (if it is possible in this case).

Please, help.

Upvotes: 0

Views: 155

Answers (0)

Related Questions