vkhorikov / DddAndEFCore

Source code for the DDD and EF Core Pluralsight course
https://enterprisecraftsmanship.com/ps-ef-core
MIT License
249 stars 90 forks source link

Question: How to handle an invariant that references data outside the Aggregate Root? (EG: Unique Email) #12

Closed DarrenGrafton closed 2 years ago

DarrenGrafton commented 2 years ago

Hi Vladimir,

I am looking for your opinion on how to handle an invariant such as "each Student's email must be unique".

If you move the Aggregate Root to be the full list of students, it could deliver poor performance, and would be a big change just to accommodate this rule.

Is this a rule that would have to be checked in the domain services or application services layer?

Any tips or ideas would be helpful

Thanks for the course!

Darren

vkhorikov commented 2 years ago

Check out this article series, I've explored this topic in full there: https://enterprisecraftsmanship.com/posts/domain-model-purity-completeness/