CJCMS series-plug-in ideas in projects (1)

Source: Internet
Author: User

Currently, the basic architecture trend of the Project is easy to expand. The main implementation method of easy to expand is plug-ins. All the extension modules in the project are regarded as a plug-in, the most important thing is how to combine the plug-in with the parent. Next I will discuss my understanding and implementation of the plug-in project. At the same time, due to my limited ability, there may be many problems. Please criticize and correct me.

 

I think plug-ins are a separate project, which is finally integrated into a parent project. The logic code in the background does not need to be separated at all, just use the namespace to separate the code, as long as you do the separation on the UI, of course, some of the requirements are relatively high, it is written separately from the UI to the logic, but I don't think it is necessary here. Readers can do it according to their own requirements.

 

Go straight to the topic. Let's talk about the subject structure of the example I wrote. Let's take the solution directly and see how to layer it.

 

As I am keen on learning DDD, I used the idea of DDD to implement this example. I will not explain it for DDD. I can refer to the specific article. Among them, the main one is 03Plugins, which is placed in the UI of all the plug-ins, and the logic code is put in 05Applaction.

Next, let me talk about how to use the plug-in the main project, that is, "site merging ". I use MVC in the UI Layer, so the key to merging is the merge of routes and how plug-in routes enter the main project.

In the Framework of 06Foundation, I implemented this method.

 

The following is an example of a blog plug-in:

IPlugin. cs

// Author: Ignore Me CJ // mail: 869722304@qq.com (only support business cooperation negotiations) // Creation Time: 2012-08-8 // last modification time: 2012-08-11 // The copyright of the unmodified file belongs to the original author, but you can read, modify, and debug the file. This project is not recommended for commercial use and cannot ensure stability. // The original author is not responsible for all problems caused by the project. /// All the class libraries referenced in this project still follow the original agreement and shall not infringe on its copyright. /// once downloaded, you are deemed to have read this statement. //// You cannot remove all declarations from the project. Using System; using System. collections. generic; using System. linq; using System. text; using System. web. routing; namespace CJCMS. framework. plugin {public interface IPlugin {// <summary> // plug-in name // </summary> string PluginName {get; set ;} /// <summary> /// plug-in description /// </summary> string Describtion {get; set ;} /// <summary >/// plug-in Route /// </summary> List <Route> routes {get; set ;}}}

Plug-in management class:

// Author: Ignore Me CJ // mail: 869722304@qq.com (only support business cooperation negotiations) // Creation Time: 2012-08-8 // last modification time: 2012-08-11 // The copyright of the unmodified file belongs to the original author, but you can read, modify, and debug the file. This project is not recommended for commercial use and cannot ensure stability. // The original author is not responsible for all problems caused by the project. /// All the class libraries referenced in this project still follow the original agreement and shall not infringe on its copyright. /// once downloaded, you are deemed to have read this statement. //// You cannot remove all declarations from the project. Using System; using System. collections. generic; using System. linq; using System. text; using CJCMS. framework. routes; namespace CJCMS. framework. plugin {public class PluginsManger: IPluginsManger {// <summary> // install the plug-in /// </summary> /// <param name = "plugin"> </param> /// <returns> </returns> public bool InstallPlugin (IPlugin plugin) {try {// register RoutesRegister re = new RoutesRegister (); re. registerRoute (plugin. routes); // record the plug-in Table // return true;} catch {return false ;}} /// <summary> /// uninstall the plug-in /// </summary> /// <param name = "plugin"> </param> /// <returns> </returns> public bool UnInstallPlugin (IPlugin plugin) {try {// uninstall route RoutesRegister re = new RoutesRegister (); re. deleteRoute (plugin. routes); // record the plug-in Table // return true;} catch {return false ;}}}}

 

BlogPlugin

// Author: Ignore Me CJ // mail: 869722304@qq.com (only support business cooperation negotiations) // Creation Time: 2012-08-8 // last modification time: 2012-08-11 // The copyright of the unmodified file belongs to the original author, but you can read, modify, and debug the file. This project is not recommended for commercial use and cannot ensure stability. // The original author is not responsible for all problems caused by the project. /// All the class libraries referenced in this project still follow the original agreement and shall not infringe on its copyright. /// once downloaded, you are deemed to have read this statement. //// You cannot remove all declarations from the project. Using System; using System. collections. generic; using System. linq; using System. web; using CJCMS. framework. plugin; using System. web. routing; using System. web. mvc; namespace CJCMS. plugin. blog {public class BlogPlugin: IPlugin {public List <Route> routes {get; set ;} /// <summary> /// plug-in name /// </summary> public string PluginName {get; set ;} /// <summary> /// plug-in description /// </summary> public string Describtion {get; set;} public BlogPlugin () {routes = new List <Route> ();/** Route example routes. add (new Route ("User/Login", new RouteValueDictionary (new {controller = "User", action = "Login"}), new System. web. mvc. mvcRouteHandler (); */routes. add (new Route ("{controller}/{action}/{id}/{k}", new System. web. mvc. mvcRouteHandler ()));}}}

 

This can be called when the plug-in is loaded in the main project.

 

Using System; using System. collections. generic; using System. linq; using System. web; using System. web. mvc; using System. web. routing; using CJCMS. framework. plugin; using CJCMS. plugin. blog; using CJCMS. core; namespace CJCMS. web {// Note: Instructions on enabling IIS6 or IIS7 Classic mode, // visit the http://go.microsoft.com /? LinkId = 9394801 public class MvcApplication: System. web. httpApplication {public static void RegisterRoutes (RouteCollection routes) {routes. ignoreRoute ("{resource }. axd/{* pathInfo} "); routes. mapRoute ("Default", // route name "{controller}/{action}/{id}", // URL with parameters new {controller = "Home ", action = "Index", id = UrlParameter. optional} // default parameter value);/*** register the plug-in example. here you should register the selected plug-in during installation. Of course, enable the plug-in when the project is running, also, register * IPluginsManger ipm = new PluginsManger (); IPlugin blogplugin = new BlogPlugin (); ipm. installPlugin (blogplugin); */IPluginsManger ipm = new PluginsManger (); IPlugin blogplugin = new BlogPlugin (); ipm. installPlugin (blogplugin); // AutofacRepositity auto = new AutofacRepositity (builder); // auto. registerRepositity ();} protected void Application_Start () {AreaRegistration. registerAllAreas (); RegisterRoutes (RouteTable. routes );}}}

 

 

Finally, remember to copy the plug-in UI to the main project and add the compiled command

 

 

xcopy /s /y "$(ProjectDir)bin\*" "$(SolutionDir)CJCMS.Web\bin\"xcopy /s /y "$(ProjectDir)Content\*" "$(SolutionDir)CJCMS.Web\Content"xcopy /s /y "$(ProjectDir)Scripts\*" "$(SolutionDir)CJCMS.Web\Scripts"xcopy /s /y /i "$(ProjectDir)Views\*" "$(SolutionDir)CJCMS.Web\Views\Blog"

 

 

Maybe this code

xcopy /s /y /i "$(ProjectDir)Views\*" "$(SolutionDir)CJCMS.Web\Views\Blog"

You can see some clues. Well, the next lecture is about the speaker's sentence. I 'd like to sell it first.

We hope that Daniel will provide guidance and suggestions.

 

Just waiting. Go on coding.

 

 

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.