title: Constructor injection in application where dependencies might not be able to be initialized
body: <p>My application is able to start without a database connection, how do I handle this with IoC and constructor injection?</p>
  
  <p>Example:</p>
  
  <pre><code>public class ApplicationShellPresenter(IRepository repository, IView view)
  {
  
  }
  </code></pre>
  
  <p>When IRepository in this case will be constructed an exception will be thrown due to underlaying DAL cannot find config/file, wrong username/password etc. etc.</p>
  
  <p>With this in mind I came to the conclusion that I cannot inject the repository in the constructor OR inject anything that eventually along the line have IRepository as dependency.</p>
  
  <p>I need to start without IRepository dependency and when the user have made the correct database settings, register the IRepository in the container. But then I have already left the composition root.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>My problem was not really a IoC/Constructor injection - problem but rather a design flaw in our underlaying DAL.</p>
  
  <p>Our DAL is constructing itself upon creation. And thats why that design didn't work because I couldn't construct a IRepository dependency without constructing our DAL-engine.</p>
  
  <p>My simple solution was to wrap our DAL so it didn't construct itself upon creation.</p>