如何在DDD中组织Web服务访问?

时间:2013-07-28 18:05:22

标签: json domain-driven-design

我是DDD的新手。

现在我正在开发一个项目,要求我访问一个Web服务API,其中返回JSON并用于保存我的实体。

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

实现这一目标应该遵循哪些最佳实践。

我是否需要一项负责给我的实体充气并坚持下去的服务?

我有点困惑。

提前致谢。

1 个答案:

答案 0 :(得分:3)

您是否阅读了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
}