我是 DDD 的新手。
现在,我正在开发一个需要访问 Web 服务 API 的项目,该 APIJSON会返回并用于保存我的实体。
我的问题是访问网络服务属于哪一层?
以及应该遵循哪些最佳实践来实现这一点。
我是否需要一个服务来负责膨胀我的实体并将它们持久化?
我有点困惑。
提前致谢。
我是 DDD 的新手。
现在,我正在开发一个需要访问 Web 服务 API 的项目,该 APIJSON会返回并用于保存我的实体。
我的问题是访问网络服务属于哪一层?
以及应该遵循哪些最佳实践来实现这一点。
我是否需要一个服务来负责膨胀我的实体并将它们持久化?
我有点困惑。
提前致谢。
你读过Repository Pattern吗?</p>
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
}