Search code examples
domain-driven-designddd-repositories

Loading a Value object in List or DropdownList, DDD


I need to clarify something.

Have Person Aggreagate , 2 VOs (Country, StateProvince).

I want to load all country in my presentation layer (i am using mvc)

Evan says you only use repository (IPersonRepository) to work with root entity (it should always return just a reference to the Aggregate Root)

   public interface IPersonRepository()
   {
     void savePerson(Person p);
     void removePerson(Person p);
     Ilist<Person> getPerson();
   }

what i usually do to solve this :

Add in IPersonRepository this method

IList<Country> LookupCountrysOfPerson();

In Infra layer implement the Domain interfaces like this:

public IList<Person> LookupCountrysOfPerson()
{
    return Session.CreateQuery("from Countrys").List<Person>());
}

My partner says im wrong.

Sometimes you have to sacrifice your domain model in order to accomplish some task

What is the best way to do this?

with code please! :)


Solution

  • Evans also says (pg 170) "An entity as basic as Location may be used by many objects for many reasons..."

    I would also consider making Country an entity for the reasons given above. Perhaps more importantly, it is a low level object. You probably are also even supplying Country by configuration rather than through any actual domain activities. Therefore I would remove it from the Person and make it a standalone entity.

    Also for this type of object you may not really need a dedicated repository, consider creating a single lookup service that provides query access for a group of similar objects of this nature.