High performance IOC plug-in architecture based on. NET MVC (ii) Plug-in loading principle

Source: Internet
Author: User

The previous post briefly introduced the following plug-in code composition Department: http://www.cnblogs.com/gengzhe/p/4390932.html

This blog mainly explains the implementation of the principle of plug-ins, first of all to explain a few concepts:

First, the contract

Plug-ins and systems must have a contract, the system can find plug-ins and load plug-ins correctly, I use all plug-ins are implemented Sun.core inside the IPlugin interface.

Second, the Readme

When the plugin is loaded, it needs to tell the system what type of plugin I am, my GUID, the assembly I rely on, my status and permissions, my configuration information, and so on, this behavior is the plugin's self-description, referred to as the README.

Third, the configuration

Plug-ins must be able to be configured (usually at the time of installation or before the system boot configuration), the use of plug-in configuration is generally: System Discovery plug-in-"load plug-in" load plug-in configuration file-"The configuration information into the plug-in implementation of the IPlugin interface class to initialize the plug-in.

---------------------------------------------------------------------------------------

Plug-in use process: plug-in development (can also be downloaded through the plugin warehouse required plug-in)-"plug-in zip file upload-" Configuration plugin-"Enable plug-in

With the process, I have followed the process step after step to analyze the implementation principle:

First, plug-in development

1. The plug-in must have a class implementation sun.core inside the interface, this interface contains initialization, start, stop, unload several methods, because only the plug-in themselves to understand themselves, so these features need to provide plug-ins themselves, the system is only responsible for the use.

2. The plugin must provide the Pluginconfig.json file, which has a fixed format for providing configuration information to the system and saving the user's settings.

Second, the plugin upload

Step1: The plugin is compressed into a zip file, and the upload is saved under the Pluginzips folder.

Step2: Automatically unzip plug-in files to plugintemp (plugin detection temp directory).

Step3: Detects if the plug-in contains the IPlugin implementation and whether the Pluginconfig.json file is included, if it continues to execute, delete the temporary file and the zip file if it does not exist, and feedback the plug-in error message.

STEP4: Through the plug-in configuration file, copied to the plugins (plugin storage directory) under the corresponding plug-in category directory.

..... (Load plug-in)

Third, plug-in loading

1. System Boot Load

Step1: Traverse all plug-in files under the plugins directory, read the list of Pluginconfig objects and save the list information to the plug-in manager for administrative calls.

Step2: Filter out the plug-ins in pluginconfig that have status identified as error.

Step3: The plug-in assembly and the dependencies of the non-existent system in the Bin directory of the assembly loaded into the App_Data directory under the plugins directory (for unified loading and does not affect the original plugins directory of the plug-in modification, deletion).

STEP4: Load the plugin assembly and dependent assemblies (if you use IOC, you need to register the assembly with the IOC container).

STEP5: Invokes the implementation class of the IPlugin under the Assembly, performs initialization, and if the plug-in state is started, the plugin can be started directly.

2. Upload plugin load (single)

The loading of the upload plugin differs from the boot load in that the former does not need to traverse, as in the other steps.

Note: If you use the IOC container, you need to register the new assemblies with the IOC container and reset the container.

Iv. Plug-in management

Because the plug-in's configuration information and IPlugin objects have been saved during the plugin loading process, this is relatively simple. Lists allow you to filter startup, deactivation, and exception plug-ins, and you can invoke the IPlugin object directly to start, deactivate, and unload plugins.

Here is a brief introduction to this day, and the following articles will be more and more fine.

  

High performance IOC plug-in architecture based on. NET MVC (ii) Plug-in loading principle

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.