Skip to content

10. Replacing objects

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

###Replacing objects in a container

Yadic gives you a way to replace existing objects in a container. You may find it useful when writing tests. All you need to do is to get a reference to your container and replace e.g. a heavyweight object used in a production system with a lightweight equivalent.

container.add(DB.class, OracleDB.class);
container.replace(DB.class, H2DB.class); 

If you want to verify if a container contains a given object before you replace it, you can use a contains method:

if(container.contains(DB.class)) { ... }

Clone this wiki locally