of IV of NopCommerce Architecture Analysis Realizes Flexible Plug in Mechanism Based on Routing

  • 2021-07-16 02:15:57
  • OfStack

NopCommerce supports flexible plug-in mechanism, so-called Web system plug-in, in fact, it can be used like part 1 of the original system.

The usage of Web system is that the client sends a request and the server parses it. In asp. net MVC, the parsing of client requests is realized by routing.

Routing is the parsing process of the request path when the client requests.

Register all routing classes in Global. asax. cs:


//register custom routes (plugins, etc) 
var routePublisher = EngineContext.Current.Resolve<IRoutePublisher>(); 
routePublisher.RegisterRoutes(routes); 

IRoutePublisher: A route publisher that actively adds routes to the system. The entity class is: RoutePublisher.

IRouteProvider: Routing provider, one for each plug-in, registers routes to the system.

The route publisher (IRoutePublisher) uses IOC to find the route provider in the runtime path, that is, to find all classes that inherit from IRouteProvider. The routing provider of each plug-in then registers the route of this plug-in with the system.

PluginManager: The plug-in manager, which loads the plug-in's DLL and saves all plug-in information. This manager starts at system initialization and loads all plug-ins through the Initialize method.

IPluginFinder: Plug-in finder, which finds plug-ins from the plug-in manager when used.

Every plug-in has a self-description file: Description. txt; Class PluginDescriptor is responsible for saving the parsed plug-in description or the parsed entity class of this description file.

Each plug-in integrates IPlugin interface, and the plug-in has the functions of installation and uninstallation.

~ /App_Data/InstalledPlugins. txt: Save all plug-ins loaded or installed.
~/Plugins: Directory where the plug-ins are installed.
~/Plugins/bin: Every plug-in makes a backup here.


Related articles: