Linddotnetcore~aspect aspect-oriented programming

Source: Internet
Author: User

Back to Catalog

Aspect aspect-oriented programming

The aspect-oriented programming (Aspect-oriented PROGRAMMING,AOP, which is also translated into aspects of program design, view-oriented programming, and section-oriented programming) is a term in computer science that refers to a programming paradigm. The paradigm is based on a language construct called the side (aspect, and translated), and the side is a new modular mechanism for describing crosscutting concerns (crosscutting concern) scattered across objects, classes, or functions.
The concept of the side stems from the improvement of object-oriented program design, but it is not limited to this, it can also be used to improve the traditional functions. Side-related programming concepts also include meta-object protocols, topics (subject), mixed (mixin), and delegates.

    1. Terms
    2. Interception device
    3. Log blocker
    4. Cache blocker
Terms
    1. Focus (concern): small, manageable, and descriptive software components that make sense for software engineering, and a focus is usually associated with only one particular concept or goal.
    2. Main focus point (core concern): one of the most important points of interest for software.
    3. Separation of concerns (separation of CONCERNS,SOC): the ability to identify, encapsulate, and manipulate software components that are only associated with a particular concept, target, the ability to identify, encapsulate, and manipulate concerns.
    4. Method: A software construction unit used to describe, design, and implement a given point of concern.
    5. Crosscutting (crosscut): Two concerns intersect each other, if the method that implements them has an intersection.
    6. Dominant decomposition (dominant decomposition): The main way to decompose software into modules. Traditional programming language is a linear text to describe the software, only in one way (such as: Class) to break down the software into modules, which leads to some points of interest is better captured, easy to further combine, expand, but there are some points of concern is not captured, dispersed throughout the software. Dominant decomposition is generally based on the main focus of the module decomposition.
    7. Crosscutting concerns (crosscutting concerns): In traditional programming languages, in addition to the main focus can be captured by the dominant decomposition mode, there are many points of concern that are not captured by the dominant decomposition, these concerns will be dispersed throughout the software, At this point, these concerns are crosscutting to the main focus.
    8. Side (aspect): On the basis of dominant decomposition, provides an auxiliary modular mechanism that captures crosscutting concerns in a new modular mechanism.
Interception device

Inject new code snippets before or after the execution of the method, and inject the functionality of the new snippet into the original method, where the original method needs to be an interface method or a virtual method, because we want to rewrite the original method!

Log blocker

This interceptor is relatively simple, only before the method executes, after the log behavior of the injection, do not need to return results.

Cache blocker

This interceptor is more complex than the log interceptor, which needs to return the results via the cached key, with the integration of the cache logic and cache persistence components.

Introduction to the Lindaspect cache
    • Storage: Data persistence into Redis middleware
    • Structure: Storage with Redis-hashset
    • Key prefix: lind_caching_
    • Key composition: Prefix + method name
    • HashKey: Combination of method parameters
    • Hashval: The result returned by the storage method, stored in JSON format
Code Demo
/// <summary>/// 为方法添加缓存行为/// </summary>/// <returns></returns>[CachingAspect]public virtual List<People> GetHello(){    return new List<People>    {        new People("test1","ok",DateTime.Now),        new People("test2","sad",DateTime.Now),        new People("test2","force",DateTime.Now),    };}[Fact]public void FuncInvoke(){    var fun = ProxyFactory.CreateProxy<AspectTest, AspectTest>();    var obj1 = fun.GetHello();    Thread.Sleep(1000);    var obj2 = fun.GetHello();    Assert.Equal(obj1, obj2);}

Back to Catalog

Linddotnetcore~aspect aspect-oriented programming

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.