Multiple Constructor Parameters of the Same Type in PicoContainer
One of the most important features in an Inversion of Control container for me has been the ability to bootstrap components from the container that have multiple constructor parameters of the same type, without running into amiguity problems. I want to be able to direct which specific component gets loaded first, which specific instance loads second, and so on. Some contend that my need to do this points to bad design, but I don't particularly care. I know why I need to do it this way and no other way.
Besides, PicoContainer can do this easily, so obviously I'm not the first to require this type of feature. Here's a code snippet that shows how it's done.
public void testMultiplePicoParams() throws Exception {
c.registerComponentInstance(
"lemon", new Fruit("lemon"));
c.registerComponentInstance(
"lime", new Fruit("lime"));
c.registerComponentInstance(
"bubble", new Fruit("tapioca"));
c.registerComponentImplementation("lemonbubble",
Juice.class, new Parameter[] {
new BasicComponentParameter("lemon"),
new BasicComponentParameter("bubble")});
Juice lemonbubble = getJuice("lemonbubble");
Assert.assertEquals(
"lemon", lemonbubble.getType());
Assert.assertEquals(
"tapioca", lemonbubble.getSecondIngredient());
System.out.println("w00t! Pico can properly " +
"create complex component instances.");
}
I ran this test today and it worked perfectly as I expected. The container can create objects with as many or few objects of whichever type I need in the constructor. It Just Works (TM).
Did I mention yet how happy I am with PicoContainer? Inversion of Control exactly how it should be.
