title: Dependency Injection vs Layered Architecture
body: <p>I've been reading a lot about dependency injection and the service locator (anti-?) pattern - a lot of it on StackOverflow (thanks guys :). I have a question about how this pattern works when it's within a n-layer architecture.</p>
  
  <p>I've seen a lot of blog posts where they describe injecting a IDataAccess component into the business objects. E.g.</p>
  
  <pre><code>public class Address
  {
      IDataAccess _dataAccess;
      public Address(IDataAccess dataAccess)
      {
          this._dataAccess = dataAccess;
      }
  }
  </code></pre>
  
  <p>However, I was under the impression that in an n-layer architecture, the UI layer should not need to have any knowledge of the data access layer... or even know that there /is/ a data access layer! If DI requires exposing the IDataAccess interface in the constructors of the BusinessObjects, this then exposes to the UI the fact that the Business Layer uses a data access layer under the hood - something the UI doesn't need to know or care about surely?</p>
  
  <p>So, my fundamental question is: Does DI require that I expose all my lower layer interfaces to all upper layers and is this a good or a bad thing?</p>
  
  <p>Thanks</p>
  
  <p>Edit: To clarify (after a few comments), I know my business object should be ignorant of the which specific <strong>implementation</strong> of which IDataAccess it uses (hence the Dependency being injected in the constructor) but I thought that the layers above the BO should not know that the Business Object even <strong>requires</strong> a dependency on a DAL.</p>