最近准备入职,同事说过去参与一个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#编程语言实现的一个屏幕拾色器程序,名为ColorSnap,提供了完整的源代码,并且经过测试,功能正常。 C#是一种面向对象的编程语言,由微软开发,广泛应用于Windows平台的应用程序开发。它具有丰富的类库...
一篇名为“拾起身边的阳光”的作文,生动地描绘了作者在生活与学习中遇到挫折时,如何从母亲、老师和朋友那里汲取力量,重新找到前进的方向。 作文的第一部分讲述了作者在学业上的困境。当学习中遇到挫折,老师严厉...
在本文中,我们将深入探讨如何使用C#和WPF(Windows Presentation Foundation)开发一款具有Aero毛玻璃效果的屏幕RGB颜色拾色器。这个应用程序利用了C#的Aero类来实现美观的用户界面,并通过全局鼠标钩子来捕获并...
本项目是用C#编程语言实现的一个屏幕吸色器,功能类似于"和片云工作室工具",下面将详细介绍相关的知识点。 首先,我们来了解一下C#语言。C#是微软公司推出的一种面向对象的编程语言,被广泛应用于Windows平台的...
本文将详细介绍如何使用C#调用Windows API来实现一个拾色器,并深入探讨相关的技术细节。 首先,我们要明白Windows API是Microsoft Windows操作系统提供的一组函数、常量、数据类型等,它们允许开发者访问操作系统...
【C#屏幕截图工具源代码】是一个使用C#编程语言实现的桌面应用程序,它提供了类似QQ的屏幕截图功能。在Windows环境下,用户可以利用这样的工具快速捕获屏幕上的任何区域,并进行保存或分享。这个项目可能包含多个...
"Firebird与C#的连接及嵌入式开发" Firebird是一个开源的关系数据库管理系统,由于其高性能、可靠性和跨平台特点,广泛应用于各种软件开发中。C#是微软公司推出的一个面向对象的高级编程语言,广泛应用于Windows...
6. **事件处理**:C#事件驱动的编程模型在这里起着关键作用。例如,当用户点击屏幕或调整刻度尺时,相应的事件处理器会被触发,执行颜色选取和显示更新的操作。 7. **代码组织**:遵循良好的编程实践,如使用MVC...
特别好用的C#屏幕颜色取拾器,占用资源小,可缩放图片,另存为图片等
【C# 完成端口 IOCP 知识点详解】 在Windows操作系统中,输入输出完成端口(Input/Output Completion Port,IOCP)是一种高效、可扩展的异步I/O模型,它允许应用程序处理多个并发的I/O操作。C#作为.NET框架的一部分...
特别是在热成型塑料制品的生产中,中空产品拾起和传递装置作为实现生产自动化的关键技术,起着至关重要的作用。本篇文章将对这类装置的设计原理、应用场合及在生产流程中的重要性进行深入分析。 热成型技术是指将...
在本文中,我们将深入探讨...通过创建钩子和处理键盘、鼠标事件,我们可以创建各种实用的工具,如屏幕拾色器、全局快捷键管理器等。但要注意,这些功能的滥用可能侵犯用户隐私,因此在实际开发中应遵循道德和法律规范。
在本文中,我们将深入探讨如何使用C#编程语言创建一个颜色拾取器。颜色拾取器是一种实用工具,它允许用户获取屏幕上任何位置的颜色,并将其转换为不同的表示形式,如16进制、10进制以及HTML颜色值。在这个过程中,...
在IT领域,C#是一种广泛使用的编程语言,尤其在开发Windows桌面应用方面有着显著的优势。本项目"**C#屏幕截图+颜色拾取器**"是利用C#结合Windows API来实现的功能强大的实用工具,它将屏幕截图和颜色拾取功能巧妙地...
他没有选择以愤怒还以颜色,而是采取了一种更为智慧和尊严的方式来应对——他缓缓地弯下腰,用优雅的姿态拾起了散落在地上的钱,仿佛拾起的是自己的尊严和人格。 这一举动震惊了在场的所有人,包括那个曾断然拒绝他...
例如,编写一个函数,根据输入的数字,将“123456.78”转换成“壹拾贰万叁仟肆佰伍拾陆元柒角捌分”。理解数字到汉字的对应规则以及货币单位的使用是实现这个功能的关键。 以上五个知识点涵盖了C#编程的多个方面,...
C# 实现 比如在文本框中输入123 单击提交按钮就会显示壶百贰拾叁元等等 string[] da ={ "仟", "佰", "拾", "兆", "亿", "萬", "元" }; string[] big={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"}; string ...
初学C#的时候就曾想过写屏幕保护,当时觉得很深奥,摸不着头绪,就放弃了。今日又重新拾起,突然觉得也就是那么一回事,知道了就很简单了。好的,下面就介绍一下如何利用C#制作屏幕保护。
C#作为.NET框架中的主要编程语言,提供了丰富的字符串处理功能,可以方便地实现这种转换。下面我们将详细介绍如何在C#中进行数字到中文大写的转换。 首先,我们需要理解数字到中文大写的基本规则: 1. 零到九对应的...
本文将详细介绍如何使用C#调用灵云TTS,并完成整个流程。 首先,要使用C#调用灵云TTS,你需要引入必要的库文件。在提供的压缩包中,`Szzt.Voice.Hci.dll`和`Szzt.Framework.Interface.dll`是捷通华声灵云TTS的C#...