"Dynamic substitution" of plugins

Source: Internet
Author: User

Imagine a scenario in which our service system provides a range of functional services, and more new functional services will be added in the future, and there may be situations where functional services need to be changed or removed. A common basic requirement for such a service system is the operation of a service system that cannot be stopped when adding/removing/updating a feature service. In general, the encapsulation of each service into a single plug-in DLL makes it very easy to implement plug-in hot-swapping (see here for the basic information about plug-ins), but the plugin's "Hot Swap" ("Dynamic Substitution") is a problem. The reason is that when we unload the plug-in DLL from the service system, the service system still holds the underlying reference to the DLL, and if you try to delete or overwrite the dll,windows it will give you a message similar to "the DLL is being used."

So how to solve this problem? I think there are at least two options:
(1) Use the AppDomain. Load the plug-in in a new AppDomain, and then uninstall the AppDomain to cleanly unload the plug-in DLL from the AppDomain from the service system. The drawback of this scenario is the need to manage a large number of AppDomain (because you have a multitude of functional services), and the cross-AppDomain communication is done in a remoting way, which will introduce a lot of unnecessary trouble to our system. If you are interested, you can try this option, and I prefer the second one.

(2) Copy the plug-in DLL in memory, and then load the in-memory DLL. This way, the DLL on the hard disk can be overwritten or deleted arbitrarily. Previously we were loading the plug-in DLL directly from the hard disk, just like this:

Assembly asm = Assembly.LoadFrom (Addinfilepath);   

Now, we need to turn a corner:

Assembly asm  null  ;                                  // Copy the plug-in to the memory buffer first                byte NULL  ;                                     if (Filehelper.readfiletobuff (Addinfilepath, out addinstream))                {                    // load DLL in memory                }

This solves the problem of "dynamic substitution" of the plugin.

Reference Links:

"Dynamic substitution" of plugins

Enterprise-Class Server design and implementation experience of the plug-in System Foundation

"Dynamic substitution" of plugins

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.