通过DDD应用程序从REST api返回域模型是否很好? [英] Is it good to return domain model from REST api over a DDD application?

查看:82
本文介绍了通过DDD应用程序从REST api返回域模型是否很好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果要在DDD App的CRUD之上有一个REST层,是否要让REST层吐出域模型(就数据而言)(例如GET)?

If you were to have a REST layer on top of your DDD App for CRUD, would you let the REST layer spit out domain model(in terms of data)(say for a GET)?

推荐答案

通常,您希望能够更改域对象(例如,当您学习有关该域的新知识时),而不必更改系统的公共接口/ API。反之亦然:如果需要对公共接口进行更改,则不必更改域模型。

Generally, you'd want to be able to change your domain objects (for instance when you learn something new about the domain), without having to change a public interface/API to your system. Same thing the other way around: if a change is required to a public interface, you don't want to have to change your domain model.

所以从这个角度来看,我永远不会通过公共接口按原样公开我的域对象。相反,我将创建属于公共接口的数据传输对象(DTO)。这样,对我的域和公共api的更改就可以独立更改。

So from this perspective I'd never expose my domain objects as-is over a public interface. Instead I'd create data transfer objects (DTO) that are part of the public interface. This way, changes to my domain and public api can change independently.

这篇关于通过DDD应用程序从REST api返回域模型是否很好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆