bet*_*all 8 oop domain-driven-design business-logic repository-pattern
采取这个简单,人为的例子:
UserRepository.GetAllUsers(); UserRepository.GetUserById();
不可避免地,我会有更复杂的"查询",例如:
//returns users where active=true, deleted=false, and confirmed = true
GetActiveUsers();
Run Code Online (Sandbox Code Playgroud)
我无法确定存储库的责任结束的位置.GetActiveUsers()表示一个简单的"查询". 它属于存储库吗?
涉及一些逻辑的东西怎么样,例如:
//activate the user, set the activationCode to "used", etc.
ActivateUser(string activationCode);
Run Code Online (Sandbox Code Playgroud)
存储库负责对对象集进行特定于应用程序的处理。这自然涵盖查询以及设置修改(插入/删除)。
ActivateUser
对单个对象进行操作。需要检索该对象,然后对其进行修改。存储库负责从集合中检索对象;另一个类将负责调用查询并使用该对象。