Spring.net Study Notes (6)-Method injection

Source: Internet
Author: User

First, the development environment

System: WIN10

Compiler: VS2013

Ii. involving the Assembly

Spring.Core.dll 1.3.1

Common.Logging.dll

III. development Process 1. Project structure

2. Writing Mobile.cs
namespace springnetmethoddi{    publicabstractclass  Mobile    {        //  can be virtualpublic        abstract  sendtool getsendtool ();}    }
3. Writing SendTool.cs
namespace springnetmethoddi{    publicclass  sendtool    {         public  void  WeChat ()        {            Console.WriteLine (" I am kimisme, I am using hair information " );        }    }}
4. Writing RealOp.cs
namespace springnetmethoddi{    publicclass  realop    {         public  Virtualstring Buy (string  goods)        {            return' It's the rest of yesterday. " ;        }    }}
5. Writing SuperMarket.cs
namespace springnetmethoddi{    publicclass  supermarket:imethodreplacer    {          Public Object Implement (objectobject[] arguments)        {            string value = arguments[0]. ToString ();             return " It's today's bread. " ;        }    }}
6. Writing Door.cs
namespacespringnetmethoddi{ Public Delegate stringOpenhandler (stringArg);  Public classDoor { Public EventOpenhandler Openthedoor;  Public voidOnOpen (stringArg) {            if(Openthedoor! =NULL) {Console.WriteLine (Openthedoor (ARG)); }        }    }}
7. Writing Men.cs
namespace springnetmethoddi{    publicclass  men    {        publicstring the Openthisdoor (string  arg        )            {return parameter is: " + Arg;}}    }
8. Write the app. Config
<?XML version= "1.0" encoding= "Utf-8"?><Configuration>  <configsections>    <sectiongroupname= "Spring">      < Sectionname= "Context"type= "Spring.context.support.contexthandler,spring.core"/>      < Sectionname= "Objects"type= "Spring.context.support.defaultsectionhandler,spring.core"/>    </sectiongroup>  </configsections>  <Spring>    <Context>      <ResourceURI= "Config://spring/objects"></Resource>    </Context>    <Objectsxmlns= "Http://www.springframework.net">      <!--01 Abstract Method Injection -      <Objectname= "Sendtool"type= "Springnetmethoddi.sendtool,springnetmethoddi"></Object>      <Objectname= "mobile"type= "Springnetmethoddi.mobile,springnetmethoddi">        <Lookup-methodname= "Getsendtool"Object= "Sendtool"/>      </Object>      <!--02 Replacement Method -      <Objectname= "Replacevalue"type= "Springnetmethoddi.supermarket,springnetmethoddi"></Object>      <Objectname= "Realop"type= "Springnetmethoddi.realop,springnetmethoddi">        <Replaced-methodname= "Buy"Replacer= "Replacevalue">          <Arg-typeMatch= "String"/>        </Replaced-method>      </Object>      <!--03 Event Injection -      <ObjectID= "Door"type= "Springnetmethoddi.door,springnetmethoddi"></Object>      <ObjectID= "Men"type= "Springnetmethoddi.men,springnetmethoddi">        <ListenerEvent= "Openthedoor"Method= "Openthisdoor">          <refObject= "Door"/>        </Listener>      </Object>    </Objects>  </Spring>  <Startup>    <supportedruntimeversion= "v4.0"SKU=". netframework,version=v4.5 " />  </Startup></Configuration>
9. Console code
namespacespringnetmethoddi{classProgram {Static voidMain (string[] args) {Iapplicationcontext Context=Contextregistry.getcontext (); Mobile Mobile= Context. GetObject ("Mobile") asMobile; Mobile. Getsendtool ().            WeChat (); Realop op= Context. GetObject ("Realop") asRealop; Console.WriteLine (Op. Buy ("Bread")); Door Door= Context. GetObject ("Door") asDoor; Door. OnOpen ("Opening");        Console.readkey (); }    }}
Iv. remarks

Today fell into the pit, concrete what pit to see the problem summary

Spring.net Study Notes (6)-Method injection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.