Emit learning-the real story-implementing a simple AOP Framework (iii)

Source: Internet
Author: User
Tags aop emit

Today to introduce the definition and loading of configuration files, first give the contents of the configuration file, and then in detail on the meaning of the sections inside, and how to load the configuration file with the program, as follows:

Configuration file

<?xml version= "1.0" encoding= "Utf-8"
<aop>
<regeisty>
<ipreprocess>< br> <aspect id= "Addpreprocesslog" value= "YQL". Testproject:yql. Testproject.addpreprocesslog "isdefault=" true "/>
<aspect id=" verifypermission "value=" YQL. Aop:yql. Aop. Verifypermission "/>
</ipreprocess>
<ipostprocess>
<aspect id=" Addpostprocesslo G "Value=" YQL. Testproject:yql.       Testproject.addpostprocesslog "isdefault= true"/>
</ipostprocess>
<iexceptionhandler>
<aspect id= "Simplyexceptionhandler" value= "YQL". Testproject:yql. Testproject.simplyexceptionhandler "isdefault=" true/>
</iexceptionhandler>
</Regeisty>
<application>
<class id= "YQL. Testproject:yql.           Testproject.test "
<method id=" Int32 Test4 (System.String) "
<ipreprocess>
<aspect id= "Addpreprocesslog"/>
</ipreprocess>
<ipostprocess>
<aspect id= "Addpostprocesslog"/>
<aspect id= "TestException"/>
</ipostprocess>
<iexceptionhandler>
<aspect id= "Simplyexceptionhandler"/>
</iexceptionhandler>
</METHOD>
</class>
</application>
</aop>

The configuration file contains two sections, respectively, the Regeisty section and the Application section, and the Regeisty section contains the definition of the implementation class for all facets, including Id,value and IsDefault three properties: The ID represents the code for this implementation. The application section can refer to an implementation class as a primary key identifier, which must be unique; value is the specific information of the implementation class, consisting of the assembly and the full name of the class in which the middle is separated by a colon; the IsDefault property is optional, and if set to true, Indicates that a method uses this implementation class to implement a specific aspect processing without a specific definition. The application section contains information about all the methods that require special handling, first of all, the class (the information description of the class is the same as before), and then the method name, including the return value type and the parameter type. According to my idea, this configuration file should be through a configuration tool, through reflection and some of the user's selection operations to generate, of course, now this configuration tool does not exist, and left to expand later.

The next step is to load the configuration file, and we define a Aopconfigmanager class to implement the load and maintenance of the configuration file, which includes two external methods for initializing the configuration file, and providing the slice information that needs to be implanted when the method is implanted, and these two methods are implemented as follows:

Init

/// <summary>
/// 初始化配置文件信息
/// </summary>
/// <param name="configFilePath">配置文件路径</param>
public static void Init(string configFilePath)
{
    XPathDocument document = new XPathDocument(configFilePath);
    XPathNavigator rootNavigator = document.CreateNavigator();
    //初始化各个方面的配置信息
    InitAspectInfo(rootNavigator);
    //初始化非默认行为的方法的方面配置信息
    InitClassInfo(rootNavigator);
}

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.