javapicocontainer

How to replace a component via an instance of PicoContainer?


I am working in an environment where I do not control the startup of the PicoContainer, it is provided to me like this:

ApplicationManager.getApplication().getPicoContainer().getComponentInstanceOfType(Xyz.class);

My question is how I can replace a component via the PicoContainer?

Can I get a reference to the DefaultPicoContainer or a MutablePicoContainer somehow ?

Or can I just cast PicoContainer to MutablePicoContainer ?

Note: using "old" version, picocontainer 1.3

Thanks for any tips.


Solution

  • I found it was as simple as to cast to MutablePicoContainer :

    MutablePicoContainer picoContainer = (MutablePicoContainer) ApplicationManager.getApplication().getPicoContainer();
    picoContainer.unregisterComponent("a.b.c");
    picoContainer.registerComponentImplementation("a.b.c", MyComponent.class);
    

    I guess the default PicoContainer was provided as a kind of "read-only" container.