ASP. NET MVC plug-in mechanism

Source: Internet
Author: User
Tags nopcommerce

Overview

The core of Nopcommerce's plug-in mechanism is the use of BuildManager. addreferencedassembly will be added to the application domain reference using the Assembly.Load loaded plug-in assembly. The implementation can refer to the relevant files under the plugins directory of the Nop.core project in the Nopcommerce solution. Where the PluginManager.cs file is the core file, it contains the core code that handles the plug-in. Nopcommerce's comments are appreciated for its reference to the Umbraco project, and the links to the main reference articles are given. We extract the necessary implementation code directly from the implementation of nopCommerce3.5, make a simple version of the plugin system demo is used to demonstrate the plug-in of ASP, the core contains only a tag interface IPlugin, a management class PlugInManager contains 2 necessary methods Initialize and ReStart.   Architecture  New. NET solution Simpleplugin, add 2 class library projects: Simpleplugin. Plugincore, Simpleplugin.simplemvcplugin, and an ASP. NET Application project Simpleplugin.web. Simpleplugin.web Project Select the empty template and select the MVC Reference. To set dependencies and assembly references between projects: Add Simpleplugin to Simpleplugin.simplemvcplugin . Plugincore project references, add Simpleplugin to the Simpleplugin.web project . Plugincore project references. To Simpleplugin. Add a system.web reference to the Plugincore project.   1. Conventions(1) Convention "~/plugins" as the plug-in root directory. (2) Convention "~/plugins/bin" as the runtime directory under the Medium trust level. The plug-in is loaded at run time by a copy of the plug-in assembly at run time, instead of directly loading the plug-in, the replica in the runtime directory is not loaded, because the DLL file is not locked when the plugin is upgraded or deleted.
2. Base Code  to Simpleplugin. Add the following file to the Plugincore project:(1) IPlugin.cs: As an abstract interface for all plugins.
(2) PlugInManager: Responsible for loading plugins and referencing plugins. (3) Add the plugins directory and the Plugins/bin directory to the Simple.web project. Add Controllers/plugincontroller.cs to the Simple.web projectModify the Web. config and configure the probing element. Specifies that the trust level is a plug-in run-time directory under the Medium trust levels. 3. Writing plugins by adding an MVC assembly reference to the Simpleplugin.simplemvcplugin project through NuGet, you need to be aware of the consistency of the MVC version of the plugin with the MVC version referenced by Simpleplugin.plugincore. (1) Add Controllers/simplemvcplugin.cs implementation interface IPlugin(2) Add Controllers/simplepluginmvccontroller.cs(2) Add view views/simplemvcplugin/index.cshtml(3) Copy the Simpleplugin.web/views/web.config file from the Simpleplugin.web project to the root directory and the views directory of the current project. (4) set the. cshtml as well as the. config file type as content, and the build set to newer copy. (5) Set the assembly properties referenced by the Simpleplugin.simplemvcplugin project to be copied locally to false.  (6) Set the build path for the Simpleplugin.simplemvcplugin project to bin\debug\simplemvcplugin\ and bin\release\simplemvcplugin\
4. Manually deploy plug-ins to build the solution, access the Simpleplugin.web plug-ins list page:Copy the generated Simplemvcplugin folder to the Plugins folder of the Simpleplugin.web project to access Simpleplugin.web ~/plugin/ Install Access Simpleplugin.web's Plugins list pagevisit Simpleplugin.web's ~/simplemvcplugin/index page  5. Automatic Deploymentset the build path for the Simpleplugin.simplemvcplugin project to:.. The \simpleplugin.web\plugins\simplemvcplugin\ also sets debug and release two configurations. rebuild the solution to access the Simpleplugin.web plug-in list page and the ~/simplemvcplugin/index page:  6. Testing Intermediate Trust levelsSet the Level property of the trust element for Web. config to medium, which prohibits access to files outside the application directory. Rebuild the solution to access the Simpleplugin.web plug-in list page and the ~/simplemvcplugin/index page. Check the Plugins/bin directory:
  7. Test View File ModificationModify the index.cshtml under the Simpleplugin.web Project Plugins\simplemvcplugin\views\simplemvcplugin directory. To view the results of the modification:  8.Demo Download: Click to download

ASP. NET MVC plug-in mechanism

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.