Repositories in ddd should give the illusion of an in memory collection.
and
A Repository is essentially a facade for persistence that uses Collection style semantics (Add, Update, Remove) to supply access to data/objects
I've read contradicting examples on what repositories are supposed to be:
abstract class OrderRepository {
Order selectOne(String id);
}
or
abstract class OrderRepository {
Future<Order> selectOne(String id);
}
or even
abstract class OrderRepository {
Stream<Order> selectOne(String id);
}
A return type of Order
is not asynchronous, but it can be seen in this microsoft article and many others. The data has to come from a database so how could it return an Order
without the DB answer ?
I just need some clarification:
- Is the "repository" used in two different context one of which would be DDD, where the retrieval is synchronous and another where the repository is used kind of like a DAO ?
- If indeed by illusion of being in memory it really means synchronous, then how is the data populated inside the repository in the first place ?