The previous open source code is just a simple plugin implementation, supporting the plug-in hot plug, the last night accidentally thought, the native MVC provides routing characteristics such as areas and routeatrribute tags, according to previous practice, unable to parse the plug-in routing characteristics and areas, So spent two nights, the plug-in to improve to support areas and routing features, but also abandoned the web-class plug-in hot-Plug, Func-class plug-in still support hot-swappable.
The following is the process of implementing a support plug-in using the areas and routing attribute labels:
Native MVC requires two codes to be executed at startup: Arearegistration.registerallareas (); RouteTable.Routes.MapMvcAttributeRoutes (); Used to register areas and map route tags, we want to correctly parse the areas and routing features of the plug-in, and only start here. In order to find a solution, I read the source of MVC, but after reading the source, I feel very x pain, because all the custom registration method is declared to be internall, the assembly outside simply cannot be called, the following is:
Hey, no way, had to use reflection to call, I added a Sun.Framework.Plugin.MVC below the route extension method class
With this extension, you can register all controller types that use the routing feature. You can now call this method in the Imanage class, registering all the controllers in the plugin when initializing the plugin.
In addition, I also optimized the last version of the Web class plug-in implementation of the cumbersome problem, the plug-in generic route registration from the plug-in iplugin removed, and the same as native MVC under the App_start directory
This class needs to implement a custom Mvcrouteconfig abstract method in Sun.framework, which is designed to allow the plug-in to be initialized when the route is automatically registered.
In order to support the configuration data of the Areas,web class plug-in has been adjusted
The areas attribute is added to the configuration, which must provide all the area of the plug-in and the directory
This allows you to find the plug-in, controller object, controller view directory through the area name.
OK, now you can play the code happily, plug-in development is so simple
If you need more insight to download the source code
Source Address: HTTP://PAN.BAIDU.COM/S/1C0XT5XM
This version has done a lot of optimization, performance and improve a lot, welcome to add group to learn together: Group No.: 142939183
The. NET MVC plug-in framework supports native MVC's area and routing characteristics