ASP.NET MVC 1.0 + spring.net 1.2.0.20288 + NHibernate 2.0.1.4000整合笔记(二)——spring.net配置...

spring.net 配置  :
将下图中的DLL,添加引用到CMS.MVCWeb中: 
 
在web.config中加入以下代码:
1、在<configuration>   ->   <configSections>节点加入:
ContractedBlock.gif ExpandedBlockStart.gif Code
<!--spring.net 配置节点-->
<sectionGroup name="spring">
    
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
    
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
</sectionGroup>
<!--spring.net 配置节点-->






2、在<configuration>中加入:

ContractedBlock.gif ExpandedBlockStart.gif Code
<!--spring.net 配置节点-->
    
<spring>
        
<context type="Spring.Context.Support.WebApplicationContext, Spring.Web">
            <!--SP3: 此处的配置文件是指包括了Spring.NET对象定义的XML文件,而非特指.config文件 -->
            
<resource uri="config://spring/objects"/>
            <!--下面是引用.NET程序集内嵌资源时的URI语法:
      assembly://<AssemblyName>/<NameSpace>/<ResourceName>
      assembly://<程序集>/<命名空间>/<资源名称>
      SP_Manual:加入不同项目的不同xml配置信息。如:
      例:<resource uri="assembly://DZ_Portal.App/DZ_Portal.App/spring.net_bean_SysDepartMentPageAdmin.xml"/>
      
-->

            
<resource uri="assembly://CMS.App/CMS.App/web_business.xml"/>
            
<resource uri="assembly://CMS.App/CMS.App/web_web.xml"/>
    
</context>
      <!-- SP4:objects节点的xmlns元素是必需的,必须根据不同的应用添加不同的命名空间 -->

        
<objects xmlns="http://www.springframework.net">
              
<object id="DbProvider" type="Spring.Data.Common.DbProviderFactoryObject,Spring.Data">
              
<property name="Provider" value="SqlServer-2.0"/>
        
      <property name="ConnectionString" value="server=(local);uid=sa;pwd=;database=testTable;"/>
        
</object>
    
</objects>
    
</spring>
<!--spring.net 配置节点-->

3、在<configuration>   ->   <system.web>   ->   <httpHandlers>节点加入:

<!-- spring.net 配置节点 -->
    
< add  verb ="*"  path ="*.aspx"  type ="Spring.Web.Support.PageHandlerFactory, Spring.Web" />
<!-- spring.net 配置节点 -->

4、在<configuration>   ->   <system.web>   ->   <httpModules>节点加入:

<!-- spring.net 配置节点 -->
< add  name ="Spring"  type ="Spring.Context.Support.WebSupportModule, Spring.Web" />
<!-- spring.net 配置节点 -->

5、在CMS.App类库中新建两个XML文件:
web_business.xmlweb_web.xml

web_web.xml
<? xml version="1.0" encoding="utf-8"  ?>
<!--  WEB层的页面对像定义  -->
< objects  xmlns ='http://www.springframework.net' >
</ objects >

web_business.xml
<? xml version="1.0" encoding="utf-8"  ?>
<!--  业务层的对像定义 DAO & Manager  -->
< objects  xmlns ='http://www.springframework.net' >
</ objects >
6、把 web_web.xmlweb_business.xml都设置成“嵌入的资源”并 将CMS.App添加到CMS.Web引用中:



spring.net 配置完成,下面进行注入测试
7、在CMS.IBLL类库中添加一个ITestBLL接口
using  System;
using  System.Collections.Generic;
using  System.Linq;
using  System.Text;

namespace  CMS.IBLL
{
    
public   interface  ITestBLL
    {
        
void  Write();
    }
}

CMS.BLL类库添加实现
ContractedBlock.gif ExpandedBlockStart.gif Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CMS.IBLL;

namespace CMS.BLL
{
    
public class TestBLL : ITestBLL
    {
        
#region ITestBLL 成员

        
public void Write()
        {
            System.Web.HttpContext.Current.Response.Write(
"spring.net 配置成功!");
        }

        
#endregion
    }
}


CMS.BLL类库和CMS.IBLL类库添加到CMS.Web引用

web_web.xml:
ContractedBlock.gif ExpandedBlockStart.gif Code
<?xml version="1.0" encoding="utf-8" ?>
<!-- WEB层的页面对像定义 -->
<objects xmlns='http://www.springframework.net'>
  
<object id="Default" type="Default.aspx">
    
<property name="ITestBLL" ref="TestBLL" />
  
</object>
</objects>


web_business.xml:
ContractedBlock.gif ExpandedBlockStart.gif Code
<?xml version="1.0" encoding="utf-8" ?>
<!-- 业务层的对像定义 DAO & Manager -->
<objects xmlns='http://www.springframework.net'>
  
<object id="TestBLL" type="CMS.BLL.TestBLL, CMS.BLL">
  
</object>
</objects>

Default.aspx.cs:
ContractedBlock.gif ExpandedBlockStart.gif Code
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
using CMS.IBLL;

namespace CMS.MvcWeb
{
    
public partial class _Default : Page
    {
        
public ITestBLL ITestBLL
        { 
getset; }

        
public void Page_Load(object sender, System.EventArgs e)
        {
            ITestBLL.Write();
            
// Change the current path so that the Routing handler can correctly interpret
            
// the request, then restore the original path so that the OutputCache module
            
// can correctly process the response (if caching is enabled).

            
//string originalPath = Request.Path;
            
//HttpContext.Current.RewritePath(Request.ApplicationPath, false);
            
//IHttpHandler httpHandler = new MvcHttpHandler();
            
//httpHandler.ProcessRequest(HttpContext.Current);
            
//HttpContext.Current.RewritePath(originalPath, false);
        }
    }
}

测试代码添加完成~以下是运行效果:


源码下载:
      点击这里

转载于:https://www.cnblogs.com/cjnmy36723/archive/2009/08/08/1541903.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值