Keeping your Modules independent ================================= .. versionadded:: 2.2 One of the goals of using modules is to create discrete units of functionality that do not have many (if any) dependencies, allowing you to use that functionality in other applications without including unnecessary items. Doctrine 2.2 includes a new utility called the ``ResolveTargetEntityListener``, that functions by intercepting certain calls inside Doctrine and rewrite targetEntity parameters in your metadata mapping at runtime. It means that in your bundle you are able to use an interface or abstract class in your mappings and expect correct mapping to a concrete entity at runtime. This functionality allows you to define relationships between different entities but not making them hard dependencies. Background ---------- In the following example, the situation is we have an `InvoiceModule` which provides invoicing functionality, and a `CustomerModule` that contains customer management tools. We want to keep these separated, because they can be used in other systems without each other, but for our application we want to use them together. In this case, we have an ``Invoice`` entity with a relationship to a non-existent object, an ``InvoiceSubjectInterface``. The goal is to get the ``ResolveTargetEntityListener`` to replace any mention of the interface with a real object that implements that interface. Set up ------ We're going to use the following basic entities (which are incomplete for brevity) to explain how to set up and use the RTEL. A Customer entity .. code-block:: php addResolveTargetEntity('Acme\\InvoiceModule\\Model\\InvoiceSubjectInterface', 'Acme\\CustomerModule\\Entity\\Customer', array()); // Add the ResolveTargetEntityListener $evm->addEventListener(Doctrine\ORM\Events::loadClassMetadata, $rtel); $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config, $evm); Final Thoughts -------------- With the ``ResolveTargetEntityListener``, we are able to decouple our bundles, keeping them usable by themselves, but still being able to define relationships between different objects. By using this method, I've found my bundles end up being easier to maintain independently.