3
votes

My current project is organized in this way:

  • Domain Layer -> Domain objects and Repository Interfaces
  • Infrastructure -> Repository implementation
  • Application Layer -> Services in a MVVM pattern
  • Presentation -> Accessing only Service Layer and working with ViewModels

I´m using an IoC Container (SimpleInjector). My Services receives an IRepository in the constructor like:

public CustomerService : ServiceBase
{
   public CustomerService(ICustomerRepository repository, IUnitOfWork<CustomerContext> uow)
   {
     ...
   }
}

My question is:

To inject a Repository in the Service, my Presentation Layer should reference the Domain Layer. It´s ok to add this reference? Shouldn't my presentation layer have reference only to the Infrastructure and the Application layer?

1
For IoC you have to reference all of your layers in the Presentation layer (since its the only valid place for IoC bootstrapper configuration), because the Bootstrapper needs to know the concrete implementation (Infrastructure/DataAccess Layer) and interfaces (domain layer) to bind it.Tseng

1 Answers

2
votes

Yes, that's OK.

You need a reference to all components from the composition root (which usually resides in the presentation layer).

I understand it feels a bit strange at first, but you need to differentiate between a DLL-dependency and a hard class dependency. It's OK if your presentation layer depends on DLL's, it's not OK when a view depends on a SQL-repository (as an example).

I have written a blog post about this with some more information:

http://www.kenneth-truyers.net/2013/05/12/the-n-layer-myth-and-basic-dependency-injection/