1

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

Jan Muncinsky
  • 4,282
  • 4
  • 22
  • 40
Babak Golkar
  • 147
  • 9
  • 2
    Related: [Ioc/DI - Why do I have to reference all layers/assemblies in entry application?](https://stackoverflow.com/a/9503612/). – NightOwl888 Jan 14 '18 at 12:30

1 Answers1

1

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.

Joe
  • 1,327
  • 1
  • 10
  • 19