I'm learning DDD and yet I have more questions than answers.
Let's consider a model of a directory containing enormous number of files.
Here is how I see it:
Directory is an Aggregate root.
This entity should have the validation logic of checking file name uniqueness when it is added or just renamed. And File entity contains the 'SetName' logic, notifying Directory via Domain Event about name changes.
But how should Directory then work?
It is not always possible to load all files into memory. Should in this case Files repository have adhoc logic for checking name uniqueness? I suppose it is a viable decision.
However, what if some files have been already added or renamed withing current not yet commited transaction? (nothing prohibits that. Transaction boundaries are set externally in relation to business logic). Probably repository should take into account both in-memory and persisted states (merging these states can be nontrivial task.)
So, when aggregate root with all its children fits in memory - everything is fine. And as soon as you can not materialize all entities there are troubles.
I'd like to know what are the approaches for such situations. May be there is no problem at all and it is just because of my misunderstanding of the subject.