使用Apworks开发基于CQRS架构的应用程序【应用程序的配置与编译】

Apworks使用配置文件来启动整个系统。在上文中也能够看出,WCF服务在启动时,同时也启动了Apworks系统。所以,本节简要介绍这个WCF服务针对Apworks的相关配置节内容。

双击TinyLibrary.Services项目的web.config文件,根据下面的XML代码编辑该文件。

   1: <?xml version="1.0"?>
   2: <configuration>
   3:  
   4:   <configSections>
   5:     <section name="apworksConfiguration" 
   6:              type="Apworks.Config.ApworksConfigHandler, Apworks"/>
   7:     <section name="unityConfiguration" 
   8:              type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
   9:   </configSections>
  10:  
  11:   <apworksConfiguration>
  12:     <application bootStrapper="Apworks.Application.BootStrapper, Apworks"/>
  13:     <objectContainer provider="Apworks.ObjectContainers.Unity.UnityContainer, Apworks.ObjectContainers.Unity" section="unityConfiguration"/>
  14:  
  15:     <generators>
  16:       <generator name="defaultIdentityGenerator" kind="Identity" type="Apworks.Generators.SequentialIdentityGenerator, Apworks"/>
  17:       <generator name="defaultSequenceGenerator" kind="Sequence" type="Apworks.Generators.SequentialIdentityGenerator, Apworks"/>
  18:     </generators>
  19:  
  20:     <handlers>
  21:       <handler name="TinyLibraryCommandHandlers"
  22:                kind="Command"
  23:                sourceType="Assembly"
  24:                source="TinyLibrary.CommandHandlers"/>
  25:       <handler name="TinyLibraryEventHandlers"
  26:                kind="Event"
  27:                sourceType="Assembly"
  28:                source="TinyLibrary.EventHandlers"/>
  29:     </handlers>
  30:  
  31:   </apworksConfiguration>
  32:  
  33:   <unityConfiguration>
  34:     <container>
  35:       <register type="Apworks.Events.Serialization.IDomainEventSerializer, Apworks"
  36:             mapTo="Apworks.Events.Serialization.DomainEventXmlSerializer, Apworks">
  37:       </register>
  38:  
  39:       <register type="Apworks.Storage.IStorageMappingResolver, Apworks"
  40:                   mapTo="Apworks.Storage.XmlStorageMappingResolver, Apworks"
  41:                   name="DomainEventStorageMappingResolver">
  42:         <constructor>
  43:           <param name="fileName" value="DomainEventStorageMappings.xml"/>
  44:         </constructor>
  45:       </register>
  46:  
  47:       <register type="Apworks.Events.Storage.IDomainEventStorage, Apworks"
  48:                 mapTo="Apworks.Events.Storage.SqlDomainEventStorage, Apworks">
  49:         <constructor>
  50:           <param name="connectionString" 
  51: value="Data Source=.\SQLEXPRESS;Initial Catalog=TinyLibraryEventDB;Integrated Security=True;Pooling=False;MultipleActiveResultSets=True;"/>
  52:           <param name="mappingResolver">
  53:             <dependency type="Apworks.Storage.IStorageMappingResolver, Apworks" name="DomainEventStorageMappingResolver"/>
  54:           </param>
  55:         </constructor>
  56:       </register>
  57:  
  58:       <register type="Apworks.Bus.ICommandBus, Apworks" mapTo="Apworks.Bus.DirectBus.DirectCommandBus, Apworks.Bus.DirectBus">
  59:         <constructor>
  60:           <param name="dispatcher">
  61:             <dependency type="Apworks.Bus.IMessageDispatcher, Apworks"/>
  62:           </param>
  63:         </constructor>
  64:         <lifetime type="ContainerControlledLifetimeManager"/>
  65:       </register>
  66:  
  67:       <register type="Apworks.Bus.IEventBus, Apworks" mapTo="Apworks.Bus.DirectBus.DirectEventBus, Apworks.Bus.DirectBus">
  68:         <constructor>
  69:           <param name="dispatcher">
  70:             <dependency type="Apworks.Bus.IMessageDispatcher, Apworks"/>
  71:           </param>
  72:         </constructor>
  73:         <lifetime type="ContainerControlledLifetimeManager"/>
  74:       </register>
  75:  
  76:       <register type="Apworks.Bus.IMessageDispatcher, Apworks" mapTo="Apworks.Bus.DirectBus.DirectMessageDispatcher, Apworks.Bus.DirectBus">
  77:         <lifetime type="ContainerControlledLifetimeManager"/>
  78:       </register>
  79:  
  80:       <register type="Apworks.Repositories.IDomainRepository, Apworks" mapTo="Apworks.Repositories.DomainRepository, Apworks">
  81:         <constructor>
  82:           <param name="storage">
  83:             <dependency type="Apworks.Events.Storage.IDomainEventStorage, Apworks"/>
  84:           </param>
  85:           <param name="eventBus">
  86:             <dependency type="Apworks.Bus.IEventBus, Apworks"/>
  87:           </param>
  88:         </constructor>
  89:       </register>
  90:  
  91:       <register type="Apworks.Storage.IStorageMappingResolver, Apworks"
  92:                   mapTo="Apworks.Storage.XmlStorageMappingResolver, Apworks"
  93:                   name="QueryStorageMappingResolver">
  94:         <constructor>
  95:           <param name="fileName" value="QueryObjectStorageMappings.xml"/>
  96:         </constructor>
  97:       </register>
  98:  
  99:       <register type="Apworks.Queries.Storage.IQueryObjectStorage, Apworks"
 100:                 mapTo="Apworks.Queries.Storage.SqlQueryObjectStorage, Apworks">
 101:         <constructor>
 102:           <param name="connectionString" 
 103: value="Data Source=.\SQLEXPRESS;Initial Catalog=TinyLibraryQueryDB;Integrated Security=True;Pooling=False;MultipleActiveResultSets=True;"/>
 104:           <param name="mappingResolver">
 105:             <dependency type="Apworks.Storage.IStorageMappingResolver, Apworks" name="QueryStorageMappingResolver"/>
 106:           </param>
 107:         </constructor>
 108:       </register>
 109:  
 110:     </container>
 111:   </unityConfiguration>
 112:  
 113:   <system.web>
 114:     <compilation debug="true" targetFramework="4.0" />
 115:   </system.web>
 116:   <system.serviceModel>
 117:     <behaviors>
 118:       <serviceBehaviors>
 119:         <behavior>
 120:           <serviceMetadata httpGetEnabled="true"/>
 121:           <serviceDebug includeExceptionDetailInFaults="false"/>
 122:         </behavior>
 123:       </serviceBehaviors>
 124:     </behaviors>
 125:     <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
 126:   </system.serviceModel>
 127:  <system.webServer>
 128:     <modules runAllManagedModulesForAllRequests="true"/>
 129:   </system.webServer>
 130:   
 131: </configuration>

以上配置文件主要有两个configSection:apworksConfiguration和unityConfiguration,分别定义了针对Apworks框架和Microsoft Unity的配置内容。以下是Apworks框架配置的部分信息,仅供参考:

  • application:指定应用程序的启动器,它将被Apworks.Application.BootStrapperFactory类的Create方法创建
  • objectContainer:指定用于Apworks框架的IoC/DI容器适配器,目前Apworks只支持基于Microsoft Unity的适配器
  • generators:指定整个系统所使用的标识产生器与序列号产生器。如果未指定针对标识产生器的配置,则系统会默认使用Apworks.Generators.SequentialIdentityGenerator作为标识产生器;如果未指定针对序列号产生器的配置,则系统会默认使用Apworks.Generators.SequentialIdentityGenerator作为序列号产生器
  • handlers:指定定义了命令处理器与事件处理器的类型或程序集。当应用程序启动器启动系统的时候,这些处理器将被注册到系统中

注意上面配置节中的黄色高亮部分,记得在实际使用中,将其修改为实际的数据库链接字符串。

至此,我们已经完成了应用系统部分的开发任务,UI部分就是通过调用所需的WCF服务来实现其数据处理功能,因此本系列文章将不再讨论UI部分的实现方式。有兴趣的读者请直接到TinyLibraryCQRS的网站http://tlibcqrs.codeplex.com阅读完整源代码。下一讲将介绍系统的启动与运行相关内容。

使用Apworks开发基于CQRS架构的应用程序【应用程序的配置与编译】

上一篇:wget进行整站下载


下一篇:使用Apworks开发基于CQRS架构的应用程序【运行应用程序】