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