我正在使用 DDD。
我有以下接口(interface):
interface ICustomerRepository
{
void Disable(int customerId);
}
interface ICustomerService
{
void Disable(int customerId);
}
该应用程序将在 Web 服务上运行。
我想知道,我应该使用 id 作为参数还是整个 Customer 实体?
每种方法的优缺点是什么?
最佳答案
好吧,事实是这种行为不应该出现在存储库中。行为应该放在实体中。
但是,您的应用程序服务契约(Contract)可能应该免除域类。
例如
//Application service (runs in a transaction)
public void Disable(int customerId) {
var customer = this.customerRepository.FindById(customerId);
customer.Disable(); //execute business logic
this.customerRepository.Save(customer); //persist the state
}
关于c# - 实体 VS Id 作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28704015/