Skip to content

09. Duplicate types

Jim Riordan edited this page Aug 10, 2016 · 1 revision

###Duplicate types

You have to remember that you can't add the same type twice to the container.

container.add(Engine.class);
container.add(Engine.class); // will throw ContainerException 

In the example above, the container will tell you that Engine has already been added. Yadic will always keep you from adding duplicates when a call to the second add method is made.

Yadic will also not allow you to register multiple implementations of one interface:

container.add(SomeInterface.class, SomeInterfaceImpl1.class);
container.add(SomeInterface.class, SomeInterfaceImpl2.class); // exception 

In this case you should rethink the way you model your system. Maybe there's a separate interface waiting to be extracted.

Clone this wiki locally