title: Symfony2, Dynamic DB Connection/Early override of Doctrine Service
body: <p>I have a Core config Database, each row is an 'App' with some basic config etc.<br>
  Once you have chosen your app, I want to connect to a database using a property of that row (ID), and the host may also change based on the row.</p>
  
  <p>What I want is to register a service that sets up the Doctrine service using these details if you are in a place on the site that it's required (which I know based on URI).</p>
  
  <p>I am using the Entity manager, and various Doctrine Listeners/Event subs</p>
  
  <p>I've played around with the ConnectionFactory, but this appears to cause problems with the subscribers.</p>
  
  <p>What is the best way to hook something up that will transparently modify the Doctrine service, so that the controllers can act without any knowledge of which DB host and DB name they are connecting to?</p>
  
  <p>Each DB of this type will have the same structure so all Entity mapping is correct.</p>
  
  <p>I'm looking for a really clean implementation, hopefully using the Service Container to avoid any 'hacks'.</p>
  
  <p>Does anyone have any knowledge of doing this?</p>