title: DDD and Dependency Injection
body: <p>I'm currently trying to 'marry' the DDD pattern with dependency injection (using Ninject), but I feel I'm breaking fundamental principles by doing so.</p>
  
  <p>I've have a console application that hosts the NancyFX web framework on top of OWIN to provide a configuration interface. My project structure is as following:</p>
  
  <pre><code>Infrastructure
      - Infrastructure.Core
          - Repositories
          - Mappings
      - Infrastructure.Media
          - Media Services
  
  Core
      - Logging &amp; Exception-Handling intercaces
  
  Domain
      - Entities
      - Repositories
      - Services
  
  App
      - Main application
  
  Web
      - Web Frontend (Nancy Modules, Models etc.)
  </code></pre>
  
  <p>Since I'm DIying (heh...) all over the place (injecting contexts into repositories, resolving singleton services...), I've created a static class in my <strong>App</strong> project that creates a IKernel instance and registers all the dependencies at the application startup.</p>
  
  <p>I've got some repositories that will be accessed in Nancy Modules and self hosted Web API controllers, now the first problem I face is when I would like to register the repositories in a 'per request' lifetime: IKernel.Bind().PerRequest() is only available in the Ninject.Web.Common package which depends on Microsoft.Web.Infrastructure etc.. etc.. I'm ending up creating dependencies to web specific packages in a component that basically knows nothing about my web framework or the API (except for configuring OWIN).</p>
  
  <p>Additionally, by binding domain repository &amp; services interfaces to concrete implementations from the infrastructure layer, I make my application depending on the implementations, which doesn't really feel right.</p>
  
  <p>How could I solve those issues?</p>