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.