Aspect Oriented Programming (AOP)

  1. Overview

    1. The Aspect: Aspect is usually non functional functional requirement of system such as logging , security , monitoring etc.

    2. Type of Aspects

      1. Crosscutting Aspect

        1. Authentication

        2. Authorization

        3. Caching

        4. Communication

        5. Configuration Management

        6. Exception Management

        7. Logging and Instrumentation

        8. State Management

        9. Validation

      2. Code Repetition (DRY) Aspect

      3. Code Generation Aspect

    3. Aspect Oriented Programming

      1. It is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting (Non Functional Requirements) concerns.

      2. Core objective is to increase code reuse that are not possible by conventional OOPS techniques.

      3. It helps to implement DRY Principle in more advance way beyond the capabilities of OOPS.

      4. There are several frameworks that facilitates to AOP, for example WCF exposes several hooks (extention points) that we can leverage for the purpose of attaching aspects like logging.

        1. AOP is a specific case of meta-programming.

  1. Getting Started With AOP

  1. AOP Implementation Approaches

    1. AOP implementations are technically interceptors and can be implemented using two fundamental approaches.

    2. Proxy/Decorator Based

      1. Uses some short of decorator /proxy (Dynamic Proxy) combination to achieve the goal.

      2. Easy to implement and no post compilation steps required.

      3. Implementation is based on common interface requirement that restrict the uses scenario.

      4. But advantage is that No Post Compilation steps are required.

      5. Useful for limited number of classes and methods.

      6. Most of the time implementation (Proxy/decorator) is achive via some IOC Containers.

    3. Post Compilation (Instrumentation) Based

      1. Uses IL Weaving to achieve the goal.

      2. Support very complex scenarios and aspects.

      3. Needs Post Compilation steps.

      4. Can suport large number of classes and meathod.

  1. Weaving Approachs

  2. There are basically two approaches to change the behavior of a program in .NET (i.e. to weave a .NET program):

  3. Compile-Time Weaving: the program is modified during the build process on the development machine, before deployment.

  4. Runtime Weaving: the program is modified during its execution, after deployment.

  5. Popular AOP Frameworks(Dot.Net)

    1. Post Shorp (Top Rated)

    2. Unity (Enterprise Library)

    3. Spring.Net

    4. Casel Windser

    5. NInject

  1. Comparison of AOP frameworks

  1. Specific Considerations

      1. AOP Vs Decorator Vs Proxy : AOP usually uses decorators and dynamic proxy to implement achieve it`s goal

      2. AOP and Dynamic Proxy: AOP usually uses decorators and dynamic proxy to implement achieve it`s goal

      3. AOP Vs Interceptors : Backbone of AOP is Interceptors.

      4. Interceptor Vs Proxy : Interceptors can use proxy patterns as implementation technique.

      5. Interceptor Vs Decorator : Interceptors can use decorators patterns as implementation technique that in turn may further use proxy for implementation.

      6. Decorator Vs Proxy : Technically decorator is a series of chained proxies that are defined at compile time and loaded at run time.

    1. AOP Vs AOD

      1. AOP includes programming methods and tools that support the modularization of concerns at the level of the source code,

      2. "aspect-oriented software development" refers to a whole engineering discipline.

      3. AOP and DI:Several AOP implementation technique uses DI for attaching aspect to target objects.

      4. Dynamic Proxy Vs Transparent Proxy : Transparent Proxy is a kind of Instance Proxy Generated dynamically (i.e. Dynamic Proxy) that is mainly used as interception technique by Unity Framework.

  1. AOP Books

  1. References