日期:2014-05-18  浏览次数:21220 次

Spring.net通过xml配置文件给aspx页面注入对象
最近在用spring.net 但是如何配置xml文件才可以直接将对象注入到aspx页面中?
我的配置文件
C# code

<configuration>
  <configSections>
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
      <section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler,Spring.Core"/>
    </sectionGroup>
  </configSections>
  <spring>
    <parsers>
      <parser type="Spring.Data.Config.DatabaseNamespaceParser,Spring.Data"/>
    </parsers>
    <context type="Spring.Context.Support.XmlApplicationContext,Spring.Core">
      <resource uri="~/App_Data/Spring/CommonDao.xml"/>
      <resource uri="~/App_Data/Spring/DataAccessObjects.xml"/>
      <resource uri="~/App_Data/Spring/Business.xml"/>
      <resource uri="~/App_Data/Spring/WebApplication.xml"/>
    </context>
  </spring>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpModules>
      <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
    </httpModules>
    <httpHandlers>
      <add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
    </httpHandlers>


这一部分是webconfig中关于spring的配置
C# code


<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net" xmlns:db="http://www.springframework.net/database">
  <object id="managerUser" type="AdminApplication.AdminManager.ManagerUser, AdminApplication" singleton="false">
    <property name="AdminManager" ref="adminManager" />
  </object>
</objects>



C# code

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net" xmlns:db="http://www.springframework.net/database">
  <object id="adminManager" type="BusinessLogicLayer.Admin.AdminManager, BusinessLogicLayer">
    <property name="Dao" ref="adminDao"/>
  </object>
</objects>


C# code

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net" xmlns:db="http://www.springframework.net/database">
  <object id="adminDao" type="DataAccessObjects.Admin.AdminDao,DataAccessObjects">
    <property name="AdoTemplate" ref="adoTemplate"/>
  </object>
</objects>


C# code

<?xml version="1.0" encoding="utf-8" ?>
<!--用于配置Spring,数据库连接等-->
<objects xmlns="http://www.springframework.net"
         xmlns:db="http://www.springframework.net/database">

  <db:provider id="dbProvider