DDD - what if aggregate depends on other aggregate

by eddyP23   Last Updated October 19, 2018 14:05 PM

I am modelling UserAggregate using DDD concepts. I know that two separate users should be independent, but when creating a new user, I need to validate, that there is no other user with the same username. How do I approach such a situation?

One potential solution to this is for UserAggregate to depend on IUserRepository and that way to check that the username is unique. This is clearly not ideal. Another solution would be to create UsersAggregate that contains all of the users in my system, but that is obviously absurd. Therefore I am stuck with option number 1, but still wondering what is the DDD-esque solution to this problem.



Related Questions


Domain model design

Updated July 23, 2016 08:02 AM


What is a domain?

Updated October 23, 2017 18:05 PM