c# - 实体 VS Id 作为参数

标签 c# performance domain-driven-design

我正在使用 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/

相关文章:

java - ArrayList 与数据库的 Android 速度

sql - 如何加速小型 Vertica 数据库中缓慢的多连接查询(总行数约 120K,10 分钟)

domain-driven-design - 领域服务控制粒度

authentication - DDD中的授权和身份验证(C#)

c# - DotNetOpenAuth 的教程在哪里以及如何解决其示例中的编译错误

c# - 使用绑定(bind)禁用特定的 DataGrid 单元格

c# - 如何知道任务是否同步完成?

c# - 如何在内存中初始化测试并在每个测试中使用

c# - 使用多个 Gridview C# WPF 更新 ListView

domain-driven-design - 我们都在寻找相同的 IRepository 吗?