如何利用NB代码生成工具和NBear框架,快速开发WEB项目
NBear是一个.Net 2.0下的快速开发框架。它提供了包括可视化实体设计、代码生成、持久化、SOA、MVP等一系列组件。
NBear的设计目标是尽最大可能减少程序员的重复劳动、提高开发效率、提升代码的可维护性和整体质量。
官方网站:http://nbear.org
中文教程目录索引:http://www.cnblogs.com/teddyma/archive/2006/11/07/553562.html
示例程序:从官方网站下载NBearVXXX_tutorials.zip,解压后见tutorials目录。
本文提到的NBear代码生成工具,主要是配合NBear框架更快速开发项目的一种代码生成工具。主要工具是根据数据库生成NBear框架中ServiceInterfaces层ServiceImpls层的代码。提高开发效率。接合本身NBear所带的实体生成工具,和配置文件生成工具。加上本文中的这个工具,可以大大提高项目的开发时间,开发人员只用编写跟业务有关的代码,框架相关的代码,基本上这几个工具,都可以自动生成了。
下面详细说明一下如何使用这几个工具来快速开发项目:
一、创建应用程序解决方案
1.1 打开VS2005开发环境,新建一个空的解决方案Solution。
1.2 向Solution中添加两个新建的C#类库工程,两个类库工程的名称分别为EntityDesigns和Entities,删除IDE自动创建的Class1.cs文件。
1.3 向Solution中再添加两个新建的C#类库工程,两个类库工程的名称分别为ServiceInterfaces和ServiceImpls,删除IDE自动创建的Class1.cs文件。
1.4 向Solution 中新建一个名叫WebApplication的ASP.NET Web应用程序,为WebApplication添加一个Web.config文件。
1.5 项目依赖设置:
WebApplication -> Entities, ServiceInterfaces
ServiceInterfaces -> Entities
ServiceImpls -> Entities, ServiceInterfaces
注:设置完依赖后,记得添加项目引用,并在各项目中添加NB的相关dll
1.6相关引用
WebApplication需:NBear.Common.dll,NBear.Data.dll和NBear.IoC.dll的引用
ServiceInterfacesf需:NBear.Common.dll和NBear.IoC.dll的引用
ServiceImpls 需: NBear.Common.dll,NBear.Data.dll和NBear.IoC.dll的引用
Entities需:NBear.Common. dll
EntityDesigns需:NBear.Common.Design.dll的引用,因为每一个设计实体接口必须继承自NBear.Common.Design.Entity这个接口
记得using
<shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="COLOR: blue"> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 21.0pt"><span lang="EN-US" style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一、</span><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">从数据库到实体</span><span lang="EN-US" style="COLOR: blue"> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><font color="#000000"><span lang="EN-US">1. </span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">运行</span><span lang="EN-US">NBear.Tools.DbToEntityDesign.exe</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,在</span><span lang="EN-US">Connection String</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文本框中输入下面的连接子串:</span><span lang="EN-US">Server=(local);Database=Northwind;Uid=sa;Pwd=sa</span></font></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><font color="#000000"><span lang="EN-US">2. </span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在</span><span lang="EN-US">EntitiyDesigns</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">工程中新建一个代码文件</span><span lang="EN-US">EntityDesigns.cs</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,添加</span><span lang="EN-US">using System</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</span><span lang="EN-US">using NBear.Common.Design</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设置</span><span lang="EN-US">namespace</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为</span><span lang="EN-US">EntityDesigns</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。并将刚才从</span><span lang="EN-US">DbToEntityDesign</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">复制的代码粘贴至该文件中。</span><span lang="EN-US" style="COLOR: blue"> <p></p></span></font> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><font color="#000000"><span lang="EN-US">3 </span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下面</span><span lang="EN-US">,</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对这些生成的代码做一下改造</span><span lang="EN-US">(</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">具体查询</span><span lang="EN-US">NB</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中文说明书</span><span lang="EN-US">Step 3 </span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设计实体、关系及元数据</span><span lang="EN-US">)</span></font></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="COLOR: blue"> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="COLOR: blue"> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 21.0pt"><span lang="EN-US" style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">二、</span><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">从实体设计代码生成实体代码、实体配置文件</span><span lang="EN-US" style="COLOR: blue"> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><font color="#000000"><span lang="EN-US"><span style="mso-spacerun: yes"> </span>3.1</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">编译</span><span lang="EN-US">EntityDesigns</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">工程。</span></font></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; mso-char-indent-count: 1.0; mso-char-indent-size: 10.5pt"><font color="#000000"><span lang="EN-US">3.2 </span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">运行</span><span lang="EN-US">dist</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">目录中的</span><span lang="EN-US">NBear.Tools.EntityDesignToEntity.exe</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">工具,载入</span><span lang="EN-US">EntityDesigns</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">工程编译生成的</span><span lang="EN-US">EntityDesigns.dll</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。点击</span><span lang="EN-US">Generate Entities</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">按钮</span><span lang="EN-US">,</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">将生成的代码保存到</span><span lang="EN-US">Entities</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">工程中的一个名叫</span><span lang="EN-US">Entities.cs</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的新代码文件</span><span lang="EN-US"> </span></font></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; mso-char-indent-count: 1.0; mso-char-indent-size: 10.5pt"><font color="#000000"><span lang="EN-US">3.3 </span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">点击</span><span lang="EN-US">Generate Configuration</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">按钮,将生成的代码保存到</span><span lang="EN-US">website</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">工程下的名为</span><span lang="EN-US">EntityConfig.xml</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的新文件中。</span><span lang="EN-US" style="COLOR: blue"> <p></p></span></font> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="COLOR: blue"> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 21.0pt"><span lang="EN-US" style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">三、</span><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">使用</span><span lang="EN-US" style="COLOR: blue">Nbear</span><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代码工具生成代码</span><span lang="EN-US" style="COLOR: blue"> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">打开工具后,在系统菜单中找到参数配置。配置好数据库类型及相应的链接字符串,将项目的顶级名字空间设置好(</span><span lang="EN-US" style="COLOR: red">PX.</span><span lang="EN-US" style="COLOR: #ff6600">ServiceInterfaces</span><span style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">)那这里要设置成</span><span lang="EN-US" style="COLOR: red">PX</span><span style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,导出路径设置成你项目的根目录(一般是跟解决方案</span><span lang="EN-US" style="COLOR: red">.sln</span><span style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">同一路径,这样生成时,代码自动会生成到解决方案的相应目录中,然后在</span><span lang="EN-US" style="COLOR: red">IDE</span><span style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中,点击解决方案上方的显示所有文件按钮,将生成好的</span><span lang="EN-US" style="COLOR: red">.cs</span><span style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">包括到项目中就可以了)</span><span lang="EN-US" style="COLOR: red"> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="COLOR: red"> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">工具说明:本工具用在数据库表很多时,才会发挥大的作用,主要是生成</span><span lang="EN-US" style="COLOR: #ff6600">ServiceInterfaces</span><span style="COLOR: #ff6600; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,</span><span lang="EN-US" style="COLOR: #ff6600">ServiceImpls</span><span style="COLOR: #ff6600; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这两层的代码,</span><span lang="EN-US" style="COLOR: #ff6600">ServiceImpls</span><span style="COLOR: #ff6600; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中使用了</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">partial关键字,用户自己写的代码要放在</span><span lang="EN-US" style="COLOR: #ff6600">ServiceUS.cs</span><span style="COLOR: #ff6600; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中,以免当数据库修改后,二次生成后,把用户自己写在</span><span lang="EN-US" style="COLOR: #ff6600">Service</span><span style="COLOR: #ff6600; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里的代码覆盖。</span><span lang="EN-US" style="COLOR: red"> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="COLOR: blue"> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 21.0pt"><span lang="EN-US" style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">四、</span><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">使用实体及</span><span lang="EN-US" style="COLOR: blue">NBear.Data.Gateway</span><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">访问数据库</span><span lang="EN-US" style="COLOR: blue"> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt"><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">1.</span><span lang="EN-US" style="COLOR: blue">W <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设置</span><span lang="EN-US" style="COLOR: blue">website</span><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</span><span lang="EN-US" style="COLOR: blue">Web.config</span><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件,添加一个</span><span lang="EN-US" style="COLOR: blue">entityConfig section</span><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">以包含</span><span lang="EN-US" style="COLOR: blue">EntityConfig.xml</span><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这个实体配置文件,并设置数据库连接字串。下面是设置完的</span><span lang="EN-US" style="COLOR: blue">Web.config</span><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,注意,粗体的部分都是我们添加的代码(注意修改数据库登录密码。):</span><span lang="EN-US" style="COLOR: blue"> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><?</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">xml</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"> </span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">version</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">=</span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><font color="#000000">"</font><span style="COLOR: blue">1.0</span><font color="#000000">"</font><span style="COLOR: blue"> </span><span style="COLOR: red">encoding</span><span style="COLOR: blue">=</span><font color="#000000">"</font><span style="COLOR: blue">utf-8</span><font color="#000000">"</font><span style="COLOR: blue">?> <p></p></span></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">configuration</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 1"> </span><</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">configSections</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"></span><</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">section</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"> </span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">name</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">=</span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><font color="#000000">"</font><span style="COLOR: blue">castle</span><font color="#000000">"</font><span style="COLOR: blue"> </span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span><font color="#000000">"</font><span style="COLOR: blue">Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor</span><font color="#000000">"</font><span style="COLOR: blue">/> <p></p></span></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 2"> </span><</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">section</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"> </span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">name</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">=</span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><font color="#000000">"</font><span style="COLOR: blue">entityConfig</span><font color="#000000">"</font><span style="COLOR: blue"> </span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span><font color="#000000">"</font><span style="COLOR: blue">NBear.Common.EntityConfigurationSection, NBear.Common</span><font color="#000000">"</font><span style="COLOR: blue">/> <p></p></span></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 1"> </span></</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">configSections</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 1"> </span><</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">entityConfig</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 2"> </span><</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">includes</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 3"> </span><</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">add</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"> </span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">key</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">=</span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><font color="#000000">"</font><span style="COLOR: blue">Sample</span><font color="#000000">"</font><span style="COLOR: blue"> </span><span style="COLOR: red">value</span><span style="COLOR: blue">=</span><font color="#000000">"</font><span style="COLOR: blue">~/EntityConfig.xml</span><font color="#000000">"</font><span style="COLOR: blue">/> <p></p></span></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 2"> </span></</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">includes</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 1"> </span></</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">entityConfig</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 1"> </span><</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">castle</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 2"> </span><</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">components</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 2"> </span><span style="mso-spacerun: yes"> </span><</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">component</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"> </span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">id</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">=</span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><font color="#000000">"</font><span style="COLOR: blue">CurriculumClass</span><font color="#000000">"</font><span style="COLOR: blue"> </span><span style="COLOR: red">service</span><span style="COLOR: blue">=</span><font color="#000000">"</font><span style="COLOR: blue">PX.ServiceInterfaces.ICurriculumClass, PX.ServiceInterfaces</span><font color="#000000">"</font><span style="COLOR: blue"> </span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span><font color="#000000">"</font><span style="COLOR: blue">PX.ServiceImpls.CurriculumClassService, PX.ServiceImpls</span><font color="#000000">"</font><span style="COLOR: blue">/> <p></p></span></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 2"> </span></</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">components</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 1"> </span></</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">castle</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 1"> </span><</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">connectionStrings</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 1"> </span><</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">add</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"> </span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: red; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">name</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">=</span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><font color="#000000">"</font><span style="COLOR: blue">pxinfo</span><font color="#000000">"</font><span style="COLOR: blue"> </span><span style="COLOR: red">connectionString</span><span style="COLOR: blue">=</span><font color="#000000">"</font><span style="COLOR: blue">Server=100.100.100.100;Database= info;Uid=sa;Pwd=sa</span><font color="#000000">"</font><span style="COLOR: blue"> </span><span style="COLOR: red">providerName</span><span style="COLOR: blue">=</span><font color="#000000">"</font><span style="COLOR: blue">NBear.Data.SqlServer.SqlDbProvider</span><font color="#000000">"</font><span style="COLOR: blue">/> <p></p></span></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 1"> </span></</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">connectionStrings</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-tab-count: 1"> </span><span style="mso-spacerun: yes"> </span><</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">appSettings</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">/> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><span style="mso-spacerun: yes"> </span><</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">system.web</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="COLOR: blue">5.3 </span><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">好了,到目前为止,实体设置和配置完毕了。下面我们将开始讨论</span><span lang="EN-US" style="COLOR: blue">IoC</span><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">模块的使用。</span><span lang="EN-US" style="COLOR: blue"> <p></p></span> </p> <p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">具体使用参看</span><span lang="EN-US" style="COLOR: blue">DEMO; </span></p></shapetype>