title: UnitOfWork / working with multiple databases in a DDD application
body: <p>We have an application which stores its data in two different databases. At some point in the future we may only be storing our data in one database, so we want it to be as painful as possible to make this kind of change. For this reason, we wrap our DbContexts in a single MyDataContext which gets injected into our UnitOfWork and Repository classes. </p>
  
  <pre><code>class MyDataContext : IDataContext {
      internal Database1Context Database1;
      internal Database2Context Database2;
  }
  
  class UnitOfWork : IUnitOfWork {
      MyDataContext myDataContext;
  
      public UnitOfWork(MyDataContext myDataContext) {
          this.myDataContext = myDataContext;
      }
  
      public Save() {
          //todo: add transaction/commit/rollback logic
          this.myDataContext.Database1.SaveChanges();
          this.myDataContext.Database2.SaveChanges();
      }
  }
  
  class Database1Context : DbContext {
      public DbSet&lt;Customer&gt; Customers { get; set; }
  }
  
  class Database2Context : DbContext {
      public DbSet&lt;Customers&gt; CustomerProfile { get; set; }
  }
  
  class CustomerRepository : ICustomerRepository {
      MyDataContext myDataContext;
  
      public CustomerRepository(MyDataContext myDataContext) {
          this.myDataContext = myDataContext;
      }
  
      public GetCustomerById(int id) {
          return this.myDataContext.Database1.Customers.Single(...);
      }
  }
  </code></pre>
  
  <p>My first question is, am I doing it right? I've been doing a lot of reading, but admittedly DDD is a little bit overwhelming at this point.</p>
  
  <p>My second question is which layer of the application do the IUnitOfWork and IDataContext interfaces reside in? I know that the interfaces for repositories live in the Core/Domain layer/assembly of the application, but not sure about these two. Should these two even have interfaces?</p>