域驱动编程和事件 [英] Domain driven programming and events

查看:112
本文介绍了域驱动编程和事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一些asp.net的MVC使用DDD编码。我有对象再presenting业务实体以及操作获取和添加这些服务存储库。我是新来这和我的应用程序的增长我开始看到大量的二次$ C $的C必须添加,删除或改变我的域对象/数据的结果运行。

我想打一个事件驱动的系统,其中一个动作触发code的其他部分运行。比如当我删除我希望可以订阅一些其他的事情到了这行动,使他们都在运行时删除发生的用户。

你是如何codeD您的应用程序来处理这些情况?我怎样才能建立一个可靠和一致的OO系统,我的问题?我已经知道有关事件和委托,但我更感兴趣的编码技术和好的做法。


解决方案

事情,你可能要检查出的所谓域事件。基本思路是本身触发特定领域的事件你喜欢可以订阅他们做更多的东西域之外的域模型(如 CustomerRegistered )和pretty任何东西。

乌迪大汉写了这方面的一些好的文章: 1 ,的第二,<一个href=\"http://www.udidahan.com/2008/02/29/how-to-create-fully-encapsulated-domain-models/\">3rd.

此外 - 通过Szymon 示例应用程序是对这个解释相当

CQRS是伟大的,但它影响整个架构。可能是矫枉过正。

I'm doing some asp.net mvc coding using DDD. I have objects representing the business entities and service repositories that handle fetching and adding them. I'm new to this and as my application grows I begin to see a lot of secondary code that must run as a result of adding, deleting or changing my domain objects/data.

I'd like to make an event driven system where one action triggers other parts of code to run. For instance when I delete a user I want to be able to subscribe a number of other things to this action so they all are run when a delete takes place.

How have you coded your applications to handle these situations? How can I establish a reliable and coherent OO system for my problem? I already know about events and delegates but I'm more interested in coding techniques and nice practices.

解决方案

Thing You might want to check out are so called domain events. Basically idea is that domain model itself triggers domain specific events (e.g. CustomerRegistered) and pretty much anything You like can subscribe to them to do additional stuff outside of domain.

Udi Dahan wrote some nice articles on this: 1st, 2nd, 3rd.

Also - sample application by Szymon is quite explanatory on this.

CQRS is great, but it affects whole architecture. Might be an overkill.

这篇关于域驱动编程和事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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