title: ASP.NET MVC proper layering of application and dependency injection
body: <p>I have a project that has three layer. </p>
  
  <p>1st is the DAL </p>
  
  <p>2nd is the Domain </p>
  
  <p>3rd is the Presentation</p>
  
  <p>I created an interface in my Domain Layer (ICategoryRepository) here is the Code</p>
  
  <pre><code>public interface ICategoryRepository
  {
      List&lt;CategoryDTO&gt; GetCategory();
  }
  </code></pre>
  
  <p>and I created a class in my DAL to implement the ICategoryRepository in my Domain.</p>
  
  <pre><code>public class CategoryRepository : ICategoryRepository
  {                     
      BookInfoContext _context;
  
      public List&lt;CategoryDTO&gt; GetCategory()
      {
          _context = new BookInfoContext();
  
          var categoryDto = _context.Categories
                              .Select(c =&gt; new CategoryDTO
                              {
                                  CategoryId = c.CategroyId,
                                  CategoryName = c.CategoryName
                              }).ToList();
          return categoryDto;
      }
  }
  </code></pre>
  
  <p>Then I create a class in my Domain and pass the ICategoryRepository as parameter in my constructor.</p>
  
  <pre><code>public class CategoryService
  {
  
      ICategoryRepository _categoryService;
  
      public CategoryService(ICategoryRepository categoryService)
      {
          this._categoryService = categoryService;
      }
  
      public List&lt;CategoryDTO&gt; GetCategory()
      {
          return _categoryService.GetCategory();
      }
  }
  </code></pre>
  
  <p>I do this to invert the control. Instead of my domain will depend on DAL I invert the control so that myDAL will depend on my DOMAIN.</p>
  
  <p>My Problem is, everytime I call the CategoryService in the Presentation Layer I need to pass ICategoryRepository as parameter of constructor which is in the DAL.  I don't want my Presentation Layer to be dependent in my DAL. </p>
  
  <p>Any suggestion?</p>
  
  <p>Thanks,</p>