In-depth analysis of nopcommerce plug-in

Source: Internet
Author: User

The nopcommerce plug-in mechanism is quite good, so you can analyze it and use it to integrate it into your own website architecture. Write a small article to record it. We also hope to correct the deficiencies and errors. Nop version 2.5

1. Nop. Core. plugins core folder

File directory:

 

This is the base class folder of plugins, which is the core part of the plug-in mechanism.

Ipluginfinder. CS interface:

Obtain the information interface of the plug-in. Register this interface in NOP. Web. Framework. dependencyregistrar in IOC.

The system is loaded into the memory when it is started.

// Plugins
Builder. registertype <pluginfinder> (). As <ipluginfinder> (). instanceperhttprequest ();

Iplugin. CS:

The operation interfaces of the plug-in include setting the property information of the plug-in, installing the plug-in interface, and uninstalling the plug-in interface.

Baseplugins. CSImplement iplugin. CS.

Plugindescriptor. CSThe entity class of the plug-in, including the version, description, type, file name, author, and a series of states of the plug-in.

Pluginfileparser. CSContains the entity Operation Method for the plug-in, mainly the description of the write plug-in.

Pluginfinder. CSLoad all plug-ins and obtain their information.

Pluginmanager. CSFor the main class of plug-in management, see the comments in it. Its plug-in mechanism should refer to the umbraco CMS.

2. custom plug-ins

Here I will demonstrate an empty plug-in, which is originally a write captureProgram, Time relationship, no more. Plug-in name, NOP. plugin. Crawler

Step 1: Create a class library project instead of an MVC application project.

Step 2: add the required folders and files to your project:

Controllers, required, Controller

Models. Optional. If your project is simple.

Views, optional, but generally requires an interface, which is included in the razor template.

Description.txt, which must be the version description of the plug-in. The content is as follows:

GROUP: Crawler
Friendlyname: Crawler
Systemname: NOP. plugin. Crawler
Version: 1.00
Supportedversions: 2.50
Author: nopcommerce team
Displayorder: 1
Filename: NOP. plugin. crawler. dll

Right-click on it to set properties, as shown in figure

 

 

Notes.txt, which is the remarks of the plug-in, describes the File Location of the plug-in and some precautions.

Routeprovider. CS, the routing file, inherited from NOP. Web. Framework. MVC. routes. irouteprovider

View code

Using  System. Web. MVC;  Using  System. Web. Routing;  Using  Nop. Web. Framework. MVC. routes;  Namespace  Nop. plugin. crawler {  Public   Partial   Class  Routeprovider: irouteprovider {  Public   Void Registerroutes (routecollection routes) {routes. maproute (  "  Nop. plugin. Crawler  "  ,  "  Plugins/crawler/Index  "  ,  New {Controller = "  Crawler  " , Action = "  Index "  },  New [] { "  Nop. plugin. crawler. Controllers  "  });}  Public   Int  Priority {  Get  {  Return   0  ;}}}} 

Web. config,. Net configuration file.

Crawlercontroller. CS defines a method for returning simple pages in my controller.

 
UsingSystem. Web. MVC;UsingNop. Web. Framework. controllers;NamespaceNop. plugin. crawler. controllers {[adminauthorize]Public ClassCrawlercontroller: controller {PublicActionresult index (){ReturnView ("Nop. plugin. crawler. Views. Index");}}}

You have noticed that the view path in the returned view is the view path in the plug-in. Right-click the attribute set in the View index. cshtml, And the cshtml is compiled into the DLL.

You can also set the attributes of the entire plug-in by right-clicking on the plug-in project to set the output attributes.

Finally, set the properties of the referenced DLL file. In this way, other messy files will not be copied when the DLL file is output.

Right-click the plug-in to generate only the three files

3.add the plug-in installedinins.txt of nop.webin the last step.

The plug-in name cannot be repeated and can be customized. Here, I have no special requirements for the same name as the plug-in project name.

 

You can see the background plug-in preview.

From: http://www.jqpress.com/post/178.aspx

Independent blog: http://www.jqpress.com

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.