Re: Avoid injecting Service/Repository in an Entity
Veranildo Veras <[email protected]>
| Newsgroups | gmane.comp.programming.domain-driven-design |
|---|---|
| Message-ID | <CAOZUGCLKwUkbaOzL0fni+xsJqD5p=nYVevVESq7G+JqG1MQ8VQ@mail.gmail.com> |
Hi Varun, Use the specification pattern which can be accessed on http://martinfowler.com/apsupp/spec.pdf, From what I can tell, you should locate the record of the student in the database and compare it with the data retrieved before finally including it on the database. Att, Veranildo Veras 2014-03-25 4:23 GMT-03:00 <[email protected]>: > > > Hi Everyone, > > From what I've read, this is really bad. But I have the following use case > so wondering how to do this in the proper DDD way. The business rule is > contrived but it is very similar to what i have in real life. I just cannot > disclose the use case due to NDAs. > > I have a class named Class. A class can have students in it. There is a > business rule such that if a student with the same surname belongs to any > current of any other class, they cannot be added to the class. > > So on Class, i have a method named AddStudent. Just wondering how would > the algorithm be implemented in a proper DDD sense > > public class Class > { > > public void AddStudent(Student student) > { > > // Call a repository to get all the students enrolled in all classes > // If any students surname matches the surname of the student passed in, > do not thing > // otherwise add the student > > } > > } > > > > > > -- *Veranildo Veras* *Analista / Desenvolvedor de Sistemas*