DDD 服务和 WCF 服务有什么区别?
我有一个 DDD 类库。其中,我具有以下结构:
> Core
> - DataAccess ( my LINQ repositories)
> - Domain ( my data objects)
> - Impl (my services)
我最近在我的解决方案中添加了一个 WCF 项目。该项目将 将 JSON Web 方法公开给 iPhone 客户端。 WCF 方法是 不太复杂 - GetCustomers / GetCustomerDetails / GetAlerts 获取警报详细信息/获取问题/获取问题详细信息/获取库存/ GetInventoryDetails、GetDataPoints / GetDataPointDetails / 等等...
我注意到 WCF 中的大多数方法都是公开的 通过我的 DDD 模型中的服务层。所以,我发现自己在做 很多这样的代码:
public List<Alert> GetAlerts()
{
AlertSerice _as = new AlertService;
List<Alert> alerts = _as.GetAlerts();
return alerts;
}
这对我来说感觉不对。我想知道我是否应该删除我的 Impl 文件夹(包含所有 DDD 服务)并重新编译。然后,将 DLL 添加为我的 WCF 项目中的引用并编写我的代码 以前的 DDD 服务作为 WCF 方法吗?
WCF 真的只需要域层和数据访问层吗?
提前致谢。
I have a DDD class library. In it, I have the following structure:
> Core
> - DataAccess ( my LINQ repositories)
> - Domain ( my data objects)
> - Impl (my services)
I have recently added a WCF project to my solution. This project will
be exposing JSON web methods to an iPhone client. The WCF methods are
not too sophisticated - GetCustomers / GetCustomerDetails / GetAlerts
GetAlertDetails / GetProblems / GetProblemDetails / GetInventory /
GetInventoryDetails, GetDataPoints / GetDataPointDetails / etc...
What I am noticing is that most of the methods in WCF are exposed
by my services layer in my DDD model. So, I am finding myself doing
a lot of code like this:
public List<Alert> GetAlerts()
{
AlertSerice _as = new AlertService;
List<Alert> alerts = _as.GetAlerts();
return alerts;
}
This doesn't feel right to me. I am wondering if I should be doing away with my Impl folder (with all
the DDD services) and recompile. Then, add the DLL as a refcerence in my WCF project and code my
previous DDD services as WCF methods?
Does WCF really just need the Domain and DataAccess layers?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能错误地使用了域服务。
在 DDD 中,当一个操作必须涉及多个聚合根时,会使用域服务。
GetAlerts 似乎是明显属于 AlertRepository 的功能(不仅属于该存储库,而且是该存储库的核心功能)。
至于 WCF 服务,它们是公共端点。他们的工作是接收来自客户端的请求并在域上执行命令或查询。此类服务的重点通常是转换 - 从原始类型输入参数到 DTO 输出。
It seems possible you may be using Domain Services incorrectly.
In DDD, Domain Services are used when multiple aggregate roots must be involved in an operation.
GetAlerts would appear to be functionality that clearly belongs in an AlertRepository (and not just belongs, but is the core functionality of that Repository).
As for WCF Services, they are a public endpoint. Their job is to receive requests from a client and carry out commands on the domain or queries. The focus in this sort of service is usually translation - from primitive typed input parameters to DTO's for output.
从体系结构的角度来看,使用不同的服务层来公开数据可以实现一定程度的抽象,并隔离受保护的方法和内部方法,您可以简单地插入不同的服务处理程序(服务配置)来以二进制或 XML 格式公开数据。您需要花时间的地方是确保明确定义抽象级别,并确保实现暴露于服务层的层之间的代码访问规则和安全性。
From an architectural perspective using a distinct service layer to expose your data allows a level of abstraction, and isolation for protected and internal methods, you can simply plug in a different service handler (Service configuration) to expose the data in a binary or XML format. Where you need to spend your time is ensuring the levels of abstraction are clearly defined and ensure code access rules and security between layers exposed to the service layer are implemented.