in DDD layered architecture, suppose we have UI layer that talks to Domain Model through Application Service based on ViewModel. Application Service gets generic repository through Constructor injection.

now, in UI layer for injecting generic repository, we need to add DomainModel.dll to UI project because of the type parameter of the generic repository is defined in Domain Model.

Is adding DomainModel DLL to UI layer correct, or should be in UI layer only AppService.dll referenced?

for example :

 //DomainModel.dll 

 public class StudentEntity
 {
  public long ID {get;set;}
  public string FirstName {get;set;}
  ...
 }

public interface IRepository<T>  where T :class
{
 void Insert(T enity);
 ...
}

//ApplicationService.dll

public class StudentService
{
 private IRepository<StudentEntity> _studentRep;

 public StudentService(IRepository<StudentEntity> studentRep)
 {
  _studentRep=studentRep;
 } 
 ...
}
//UI layer 

public class Main
{

     public class Program
     {
        public void Main(string[] args)
        {
            var studentService=new StudentService(??????);
// here for injecting Generic Repository we need to add domainModel.Dll to ui for access type parameter of generic repository

        }
    }

}

Best Regards

1 Answers 11

up vote 1 down vote accepted

Are you using domain objects (models, interfaces) in your UI Layer?

If Yes, then you will need the reference to your domain library.

If No, then you will be able to create a separate bootstrap project that handles all the DI and exposes its own set of objects for your UI to deal with; your UI can reference this instead.

Personally, I think the domain library should be referenced EVERYWHERE in solution, its the center of your onion after all.

Opinion: If you have ended up with a domain layer comprising of poco models that map 1:1 with your db tables and a bunch of generic CRUD repositories and rely on service classes to do all the work then you may have not being doing DDD and have just added some unnecessary abstraction to your DAL.

Not the answer you're looking for? Browse other questions tagged or ask your own question.