eXpressApp Framework 之DC技术入门系列(1)
好久没有写博客了,一个是工作忙的原因,二一个就是自己这两年的生活方面发生了太多的事情,导致自己没有精力写,最近,随着Devexpress公司的ORM框架工具XAF v20011.1的即将发布,随XAF的一个新的技术----DomainComponent(下文简称DC)也将正式发布.
以前我们用XAF开发实体对象的时候,用的最多的就是Domain Object(下文简称DO),但是,我们在使用的过程中会发现,DO有明显的局限性,比如在拓展复用方面就很是不尽如人意,特别是DO不能脱离XAF运行,这给我们的实际开发带来了成本方面的困扰,而DC在这方面就做了非常大胆的尝试,下面我们来了解下DC技术.
在这系列文章中,我将全部尽量使用DC技术进行介绍其使用方面的入门知识,并将会以一个简单采购系统作为介绍切入点,用实例让大家感受下DC能给我带来怎样的震撼
注:更多的详细信息,大家可以访问Devexpress 的官方网站http://www.devexpress.com/去了解,官网可以下载到xaf的30天试用版本,声明:提供此信息只是为了方便感兴趣的同行,仅此而已.
本次我们先来了解什么是DC?看看官方是怎么定义的:
Domain Components technology is designed to simplify data management and reusability by providing a much more flexible and abstracted approach to business object design. You can compose an application from reusable blocks, abstracted away from a particular persistence layer.
With Domain Components you define interfaces instead of regular business objects inherited from XPO classes. These interfaces will declare required properties or data fields. The way this data is to be processed ( Domain Logic) is then defined by creating special classes that determine how interface members behave when an object is constructed, when properties are changed, etc. Actual business classes are automatically implemented by XAF at runtime based on the provided logic and interfaces. You can package interfaces and domain logic in an assembly, and use it as a domain library. If you then create a new XAF application, you can reference the domain library and reuse domain components. Since interfaces support multiple inheritance, required business objects can be combined into new domain components. With interfaces you can make your domain model independent of implementation.
Domain Components Technology is not by any means a replacement for the regular business classes approach for defining domain entities. The main advantage of the technology is the ability to create reusable domain libraries containing components that can be combined in any way. If you do not need the ability to create reusable components and combine them, most probably you will not need to use Domain Components. The following list describes the benefits of the Domain Components technology and should help you decide whether or not the approach is right for your task.
-
You can create reusable domain libraries.
Most likely, each new XAF application you develop is not unique. The most common objects, such as Person, Phone, Address, etc., are always used. The Business Class Library provides you with a set of classes that you will need most frequently. But implementing your own reusable library is not a simple task. With Domain Components you can easily package an assembly and reference it in your applications.
-
You can use multiple inheritance.
Since Domain Components are represented by interfaces and not by classes, you can use multiple inheritance to combine several previously defined components into a new one. The new Domain Component will expose the properties of all its ancestors and utilize their Domain Logic. Of course you can add new properties and apply additional logic.
-
You do not need to inherit from Base Persistent Classes when implementing Domain Components.
Each regular business class is derived from one of the Base Persistent Classes in XAF. The behavior of these classes differs. For instance, a base class can either expose an auto-generated primary key property of an integer or Guid type, or not. The choice of the base class is made once a class is implemented. With Domain Components, you can use a specific base class in each new scenario (see the ITypesInfo.AddEntityToGenerate method overload that takes the baseClass parameter). However, attributes applicable to regular business classes and their properties can also be used with Domain Components. And of course, an object implemented via Domain Components does not differ from an object implemented in a standard way from the end-user or application administrator point of view.