6. Aspects - Reduce noise in source Move plumbing out of source, but keep behaviour the same AOP … doesn’t solve any new problems. is just too complex. adoption is all or nothing. Promotes sloppy design. Aspects … obscure program flow. can’t be unit tested. Debugging with Aspects is hard.
7. Aspects Lingo Advice The duplicated plumbing code we are removing Typically under 30 lines of code Behaviour that is injected at a join point Join points Places within the code where the Aspect is inserted Examples Entry/Exit of a method or property Class’s Type Definition
8. Aspects Lingo Point cut Locates Join Points to apply advice Filter driven– Automatic injection Find all Methods, of type Setter, in all classes where Namespace equals “Application.Entities” Attribute driven – Manual injection
9. Aspects Lingo Weaving Process of injecting functionality back into a component Can be performed by Text post processor – Magic comments can replaced by code Proxy container – Uses decorator pattern/hooks to allow code to be inserted Binary manipulation - Modifying assemblies - by replacing and injecting IL code
10. Existing AOP Frameworks in .NET AOP with Castle Windsor Dynamic Proxy Dynamic Proxy does the heavy-lifting of the IL generation for us Much easier for most requirements AOP with Spring.NET Can use something other than attributes such as XML configuration. Sorry, but actually I am unfamiliar with them…
22. When Can PostSharp Insert Code? PostSharp.Laos.OnMethodBoundaryAspect OnEntry OnExit OnSuccess OnException PostSharp.Laos.OnMethodInvocationAspect OnInvocation PostSharp.Laos.OnExceptionAspect OnException PostSharp.Laos.OnFieldAccessAspect OnGetValue OnSetValue
23. Other Aspects PostSharp.Laos.ImplementMethodAspect Replace a method’s content with the advice in the aspect Useful for modifying 3rd party components PostSharp.Laos.CompositionAspect Allows an interface/state to be injected into a component Used to simulate multiple inheritance Examples include Adding .NET Win Form data binding to a POCO Adding Entity Framework interfaces to a POCO
24. References PostSharp - David Ross Introduction to AOP with PostSharp - Michael D. Hall What Is PostSharp? - http://www.postsharp.org Using AOP and PostSharp to Enhance Your Code: Part A - Doron's .NET Space PostSharp - Lightweight Aspect-Oriented System - http://www.rainsts.net/