【问题标题】:How to organize web service access in DDD?如何在 DDD 中组织 Web 服务访问?
【发布时间】:2013-07-28 18:05:22
【问题描述】:

我是 DDD 的新手。

现在我正在处理一个需要我访问 Web 服务 API 的项目,其中返回 JSON 并用于持久化我的实体。

我的问题是访问网络服务属于哪一层?

为了实现这一点,应该遵循哪些最佳实践。

我是否需要一种服务来负责膨胀我的实体并将它们持久化?

我有点困惑。

提前致谢。

【问题讨论】:

  • 您的域在哪一边?在网络服务中,还是在网络服务的消费者中?
  • 该服务只提供所有必要的数据来扩充域模型。所以我会怀疑它在网络服务中。但是我在消费服务,我还没有写web服务。

标签: json domain-driven-design


【解决方案1】:

你读过Repository Pattern吗?

public class SampleEntity {

}


public interface SampleEntityRepository {

    void store(SampleEntity entity);

    SampleEntity fineBy(Identity id);

    //omitted other finders
}

使用 Web 服务适配器实现 SampleRepository。

public class WsSampleEntityRepositoryImpl implements SampleEntityRepository {
    @Override
    public void store(SampleEntity entity) {
        //transform to JSON and invoke ws
    }

    @Override
    public SampleEntity fineBy(Identity id) {
       //transform to JSON and invoke ws
       //transform JSON to SampleEntity
    }

    //omitted other finders
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多