Spring.net AOP Several terms:
Facets: For classes
Tangent point: For method
Object.xml
<?XML version= "1.0" encoding= "Utf-8"?><Objectsxmlns= "Http://www.springframework.net"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.NET/AOP"> <ObjectID= "User"type= "Testaop.user" ></Object> <ObjectID= "NewUser"type= "Testaop.newuser" ></Object> <ObjectID= "Advisor"type= "Testaop.advisor"></Object> <Aop:config> <Aop:advisorPointcut-ref= "Pointcut"Advice-ref= "Advisor"/> </Aop:config> <ObjectID= "Pointcut"type= "Spring.Aop.Support.SdkRegularExpressionMethodPointcut, SPRING.AOP"> < Propertyname= "pattern"value= "TestAop.User.Whoami"/> </Object></Objects>
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespacetestaop{ Public classAdvisor:AopAlliance.Intercept.IMethodInterceptor { Public ObjectInvoke (AopAlliance.Intercept.IMethodInvocation invocation) {NewUser NewUser=NewNewUser (); Newuser.beforewhoami (); varresult =invocation. Proceed (); Newuser.afterwhoami (); returnresult; } }}
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespacetestaop{ Public classNewUser { Public voidBeforewhoami () {Console.WriteLine ("I am before"); } Public voidAfterwhoami () {Console.WriteLine ("I am after"); } }}
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespacetestaop{ Public InterfaceIuser {voidWhoami (); } Public classUser:iuser { Public voidWhoami () {Console.WriteLine ("I am Zhangwei"); } }}
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespacetestaop{classProgram {Static voidMain (string[] args) {Spring.Context.IApplicationContext Context=NewSpring.Context.Support.XmlApplicationContext ("Objects.xml"); Iuser User= Context. GetObject ("User") asIuser; User. Whoami (); Console.readkey (); } }}
Run:
Spring.net AOP Explained