spring.net使用

 

 

1.方法

spring.net使用
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace SpringTest

{

   public class Person:IPerson

    {



        #region IPerson 成员



        public void Actor(string msg)

        {

            MessageBox.Show(msg);

        }



        #endregion

    }

}
View Code

 

2.接口

spring.net使用
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;



namespace SpringTest

{

   public interface IPerson

    {

        void Actor(string msg);

       

    }

}
View Code

 

3.调用方式

spring.net使用
using Spring.Dao;

using Spring.Data;

using Spring.Context.Support;

using Spring.Context;



private void btnSpring_Click(object sender, EventArgs e)

{

IApplicationContext ctx = ContextRegistry.GetContext();

IPerson ps = ctx.GetObject("Person") as IPerson;

ps.Actor("spring");

}
View Code

 

 

4.web.config配置

spring.net使用
<?xml version="1.0" encoding="utf-8" ?>

<configuration>



  <configSections>

    <sectionGroup name="spring">

      <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />

      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />

    </sectionGroup>

  </configSections>



  <spring>



    <context>

      <resource uri="config://spring/objects" />

    </context>



    <objects xmlns="http://www.springframework.net">

      <description>一个简单的控制反转例子</description>





      <object id="Person" type="SpringTest.Person, SpringTest" />





    </objects>



  </spring>



</configuration>
View Code

 

你可能感兴趣的:(spring)