最近准备入职,同事说过去参与一个C#的项目,蛮大的,然后我也开始深入接触。
PRO ASP.NET MVC
It’s time to rectify that, but before you go looking for the validation controls, remember
that this is an MVC application, and following the don’t-repeat-yourself principle, validation
is a model concern, not a UI concern. Validation often reflects business rules, which
are most maintainable when expressed coherently in one and only one place, not scattered
variously across multiple controller classes and ASPX and ASCX files. Also, by putting validation
right into the model, you ensure that its data integrity is always protected in the same
way, no matter what controller or view is connected to it. This is a more robust way of thinking
than is encouraged by WebForms-style <asp:XyzValidator> UI controls.
Aggregates and Simplification
Take another look at the auctions example diagram (Figure 3-4). As it stands, it doesn’t offer
much guidance when it comes to implementation with C# and SQL Server. If you load a member
into memory, should you also load all their bids, and all the items associated with those
bids, and all the other bids for those items, and all the members who have placed all those
other bids? When you delete something, how far does that deletion cascade through the object
graph? If you want to impose validation rules that involve relationships across objects, where
do you put those rules? And this is just a trivial example—how much more complicated will it
get in real life?
The DDD way to break down this complexity is to arrange domain entities into groups
called aggregates. Figure 3-5 shows how you might do it in the auctions example.
Figure 3-5. Auctions domain model with aggregates
Each aggregate has a root entity that defines the identity of the whole aggregate, and acts
as the “boss” of the aggregate for the purposes of validation and persistence. The aggregate is
a single unit when it comes to data changes, so choose aggregates that relate logically to real
business processes—that is, the sets of objects that tend to change as a group (thereby embedding
further insight into your domain model).
Objects outside a particular aggregate may only hold persistent references to the root
entity, not to any other object inside that aggregate (in fact, ID values for nonroot entities
don’t even have to be unique outside the scope of their aggregate). This rule reinforces
aggregates as atomic units, and ensures that changes inside an aggregate don’t cause data
corruption elsewhere.
In this example, “members” and “items” are both aggregate roots, because they have to
be independently accessible, whereas “bids” are only interesting within the context of an
item. Bids are allowed to hold a reference to members, but members can’t directly reference
bids because that would violate the item’s aggregate boundary. Keeping relationships onedirectional,
as much as possible, leads to considerable simplification of your domain model
and may well reflect additional insight into the domain. This might be an unfamiliar thought
if you’ve previously thought of a SQL database schema as being your domain model (given
that all relationships in a SQL database are bidirectional), but C# can model a wider range of
concepts.
A C# representation of our domain model so far looks like this:
分享到:
相关推荐
C#实现的屏幕拾色器程序,有完整的代码,功能经测试正常。
拾起身边的阳光作文.docx
用C#调用windowAPI做拾色器源码,C#拾色器
用WPF写的屏幕RGB颜色拾色器,全窗口Aero效果的对话框用C#的Aero类中一个函数实现,全局鼠标钩子用于拾色
C#屏幕吸色器 HTML颜色 RGB颜色值 和片云工作室工具类似
拾起零碎的美好
特别好用的C#屏幕颜色取拾器,占用资源小,可缩放图片,另存为图片等
弯腰拾起的尊严.doc
C#编写的屏幕截图工具源代码,类似于QQ,是另外一个C++版本的同功能实现。
C#做的拾色器,可以通过鼠标选取屏幕中的任何像素点的颜色值,还包括一个刻度尺的应用。
C#源码 编写的颜色拾取 获取当前鼠标位置的颜色 分别转换成 16进制 10进制 html的颜色值 代码内用到了通过API来改变当前鼠标样式 很容易理解
C# 实现 比如在文本框中输入123 单击提交按钮就会显示壶百贰拾叁元等等 string[] da ={ "仟", "佰", "拾", "兆", "亿", "萬", "元" }; string[] big={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"}; string ...
初学C#的时候就曾想过写屏幕保护,当时觉得很深奥,摸不着头绪,就放弃了。今日又重新拾起,突然觉得也就是那么一回事,知道了就很简单了。好的,下面就介绍一下如何利用C#制作屏幕保护。
Qml批量拾起和拖动对象,类似windows桌面批量操作
C# 完成端口 IOCP 输入输出完成端口(Input/Output Completion Port,IOCP), 是支持多个同时发生的异步I/O操作的应用程序编程接口。
【Java-Servlet】拾起海中的漂流瓶
屏幕拾色工具,和PS中拾色器功能一致,使用方便。
C#把金额转成中文字符。金额最小的4位小数厘,最大没有限制。可以到亿、兆、吉、特。 数字字符:壹,贰,叁,肆,伍,陆,柒,捌,玖,拾 小数字符:厘,毫,分,角 千以下单位:拾,佰,仟 万以上单位:万,亿,兆,吉,特,长度没...
C#金额大写转换,零壹贰叁肆伍陆柒捌玖拾佰仟万
本文档有Firebird和C#连接的方式 如何在C#中用Firebird嵌入式开发