I am working on my DDD know-what/how and have the following questions related to the Specification Pattern, the Repository Pattern, persistence agnosticism, and performance.
Consider, for the sake of simplicity:
- IAggreate, Customer,
- IRepository, CustomerRepository,
- Not using entity framework or any ORM in any way,
- Using a relational database for persistence,
- A specification which is valid only when the Customer’s first name equals the parameter X.
1 Is it not necessary for CustomerRepository to load into memory
from the database all Customer records to evaluate the specification?
2 If 1 is true, is this recommendable considering performance?
3 If 2 is a no, how should this be solved given the constraints? By not using the Specification pattern after all?
Extrapolating from the example, the problem I see is that the argument for X (the particular first name) will not be passed to the SQL WHERE clause, which causes potentially infeasible memory demands in the application.