核心:
主要利用MVC的区域功能,实现项目模块独立开发和调试。
目标:
各个模块以独立MVC应用程序存在,即模块可独立开发和调试。
动态注册各个模块路由。
一:新建解决方案目录结构
如图:
二:EasyMvc.Core即为核心库。
核心库三大主力:AreaConfig 、RouteConfig 、FilterConfig
AreaConfig :为区域启动停止以及其他状态时注入的方法,类似与Global.asax里面Application_Start、Application_End方法。
RouteConfig :路由方法,类似与App_Start里面RouteConfig方法。
FilterConfig:区域全局过滤器,针对当前路区域所有控制器的过滤(未实现)。
AreaConfig.cs
public class AreaConfig
{
public virtual void Area_Start()
{ }
public virtual void Area_End()
{ }
}
RouteConfig.cs
public class RouteConfig
{
public virtual void RegisterRoutes(AreaRoute routes)
{
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
public virtual void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
} private static Dictionary<string, RouteBase> _routes = new Dictionary<string, RouteBase>();
private static Dictionary<string, RouteConfig> _areas = new Dictionary<string, RouteConfig>(); #region Fields
public string Name { get; set; }
public string Path { get; set; }
public string[] NameSpaces { get; set; }
#endregion #region Route
public string FormatName(string name)
{
if (string.IsNullOrEmpty(name))
throw new RouteException("路由名称为空", Name);
return string.Format("{0}_{1}", Name, name);
}
public string FormatUrl(string url)
{
if (string.IsNullOrEmpty(url))
throw new RouteException("路由地址为空", Name);
return string.Format("{0}/{1}", Path, url);
}
public string[] FormatNameSpaces(string[] namespaces)
{
if (namespaces != null && namespaces.Length > )
{
List<string> list = NameSpaces == null ? (new List<string>()) : NameSpaces.ToList();
foreach (var item in namespaces)
{
if (!list.Contains(item))
list.Add(item);
}
NameSpaces = list.ToArray();
}
return null;
}
public void AddRoute(string routeName, RouteBase route)
{
if (!string.IsNullOrEmpty(routeName) && route != null)
_routes.Add(routeName, route);
} public void CheckName(string routeName)
{
if (_routes.Any(op => op.Key == routeName))
throw new RouteException("路由名称已存在", Name, routeName);
}
#endregion #region Area
public void Init()
{
Regist(RouteTable.Routes);
}
private void Regist(RouteCollection routes)
{
if (_areas.ContainsKey(Name))
throw new AreaExcption("区域已存在", Name);
_areas[Name] = this;
AreaRegistrationContext context = new AreaRegistrationContext(Name, routes);
AddNameSpaces(context);
RegisterArea(context);
if (Config.MConfig.IsDebug)
{
RegisterRoutes(routes);
}
}
private void AddNameSpaces(AreaRegistrationContext context)
{
if (NameSpaces != null && NameSpaces.Length > )
foreach (string item in NameSpaces)
{
context.Namespaces.Add(item);
}
}
private void RegisterArea(AreaRegistrationContext context)
{
AreaRoute route = new AreaRoute(this, context);
RegisterRoutes(route);
}
#endregion
}
FilterConfig.cs(未实现)
public class FilterConfig { }
三:模块重写三大核心类
App_Satrt下面的几个类,就是重写EasyMvc.Core的三大核心类的了。
AreaConfig.cs
public class AreaConfig : EasyMvc.Core.AreaConfig
{
public override void Area_Start()
{ }
public override void Area_End()
{ }
}
RouteConfig.cs
public class RouteConfig : EasyMvc.Core.RouteConfig
{
public override void RegisterRoutes(EasyMvc.Core.Routes.AreaRoute routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
public override void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
FilterConfig.cs
public class FilterConfig : EasyMvc.Core.FilterConfig { }
四:模块配置
主项目和各个模块都可配置Module.config
<?xml version="1.0" encoding="utf-8"?>
<Modules>
<IsDebug>false</IsDebug>
<Module>
<Provider>ModuleOne</Provider>
<AreaType>ModuleOne.AreaConfig</AreaType>
<RouteType>ModuleOne.RouteConfig</RouteType>
<FilterType />
<Name>ModuleOne</Name>
<Path>A</Path>
<NameSpaces>
<string>ModuleOne.Controllers</string>
</NameSpaces>
</Module>
<Module>
<Provider>ModuleTwo</Provider>
<AreaType>ModuleTwo.AreaConfig</AreaType>
<RouteType>ModuleTwo.RouteConfig</RouteType>
<FilterType />
<Name>ModuleTwo</Name>
<Path>B</Path>
<NameSpaces>
<string>ModuleTwo.Controllers</string>
</NameSpaces>
</Module>
<Module>
<Provider>MvcApplication1</Provider>
<AreaType>MvcApplication1.AreaConfig</AreaType>
<RouteType>MvcApplication1.RouteConfig</RouteType>
<FilterType />
<Name>Test</Name>
<Path>C</Path>
<NameSpaces>
<string>MvcApplication1.Controllers</string>
</NameSpaces>
</Module>
</Modules>
EasyMvc.Core AreaApplication会根据配置动态初始化执行区域方法以及各个区域的路由注册等工作。
另外AreaViewEngines会根据配置动态设置视图查找路径。
最后效果:
更多东西请查看源码,源码下面提供下载。
原文地址:http://www.cnblogs.com/deeround/p/6706683.html
源码地址:http://files.cnblogs.com/files/deeround/EasyMvc.rar
EasyMvc--让MVC区域开发更Easy(提供源码下载)的更多相关文章
-
基于Android开发的天气预报app(源码下载)
原文:基于Android开发的天气预报app(源码下载) 基于AndroidStudio环境开发的天气app -系统总体介绍:本天气app使用AndroidStudio这个IDE工具在Windows1 ...
-
Harmony OS 开发避坑指南——源码下载和编译
Harmony OS 开发避坑指南--源码下载和编译 本文介绍了如何下载鸿蒙系统源码,如何一次性配置可以编译三个目标平台(Hi3516,Hi3518和Hi3861)的编译环境,以及如何将源码编译为三个 ...
-
玩转控件:重绘DEVEXPRESS中DateEdit控件 —— 让DateEdit支持只选择年月 (提供源码下载)
前言 上一篇博文<玩转控件:重绘ComboBox —— 让ComboBox多列显示>中,根据大家的回馈,ComboBox已经支持筛选了,更新见博文最后最后最后面. 奇葩 这两天遇到 ...
-
【持久化框架】SpringMVC+Spring4+Mybatis3集成,开发简单Web项目+源码下载
上篇博文我们介绍了mybatis的基本概念与原理,这篇博文我们通过Spring与Mybatis集成,开发一个简单用户增删改查的Web项目. 基本准备工作 1.安装JDK1.6以上版本,安装与配置 2. ...
-
重磅来袭,开源Asp.Net MVC网上商城BrnShop正式发布,提供源码下载(转)
BrnShop网上商城是以Asp.Net mvc3为基础开发的网上商城,源代码完全开源(企业版的源代码目前还没有完全整理完成,一旦整理完成也全部开源). 啥话也不说了,直接上源码:下载源码(由于公司服 ...
-
openwrt开发笔记一:源码下载与编译
1.1 环境要求 编译系统:Linux发行版(本文使用Ubuntu) 编译一个可以安装的OpenWrt固件镜像文件(大约8MB大小的),你需要: 一个纯净的OpenWrt编译系统大约需要200MB的空 ...
-
C编程风格的人机交互 -- CSHELL (提供源码下载)
记得上大学时,做C语言的程序都是用sdb来调试的:再后来有了gdb,同sdb差不多,不过就好用了很多.但终究还是有点遗憾.比如,程序里设计了几个函数,如果想测试下它们,就不得不再编写个测试函数,用各种 ...
-
最新版本的Struts2+Spring4+Hibernate4三大框架整合(截止2014-10-15,提供源码下载)
一. 项目名称:S2316S411H436 项目原型:Struts2.3.16 + Spring4.1.1 + Hibernate4.3.6 + Quartz2.2.1 源代码下载地址: 基本版:ht ...
-
Android 上实现像微信一样的用Fragment来实现的Tab切页效果 提供源码下载
网有不少的例子,但是要么是像微信一样可是没有使用Fragment实现,要么是只实现了一个很简单的切换,没有下面的菜单页.这个例子有实现了,我觉得暂时够我用了##实现类:+ MainTabFragmen ...
随机推荐
-
Hibernate 基础配置及常用功能(二)
本章主要是描述几种经典映射关系,顺带比较Hibernate4.x和Hibernate5.x之间的区别. 一.建立测试工程目录 有关实体类之间的相互映射关系,Hibernate官方文档其实描述的非常详细 ...
-
那些年我们用到的jquery选择器!!
一:基本选择器 1:标签选择器: 返回值(元素集合):$("h2")选取所有h2元素. 2:类选择器:返回值(元素集合):$(".title")选取所有clas ...
-
css属性word-spacing和letter-spacing的区别
word-spacing和letter-spacing用来定义单词或者字母之间的水平空白间隔.顾名思义,word-spacing定义了单词之间的空白,例如: <div style="w ...
-
【转载】CANoe 入门 Step by step系列(一)基础应用
来源:http://www.cnblogs.com/dongdonghuihui/archive/2012/09/26/2704611.html CANoe是Vector公司的针对汽车电子行业的总线分 ...
-
CSS预处理器之less
less简单入门 w3cplus--Less讲解 vue中安装less npm install less less-loader --save 注意:在vue中引入less之后,用"> ...
-
如何将shell的打印日志输入到日志文件
如果shell打印的日志很多,屏幕无法完全显示,需要查看shell执行的情况,这是就需要输入到日值了: 如:echo "2012-6-14" | tee -a my.log -a表 ...
-
Jackson(使用注解)
jackson在实际应用中给我们提供了一系列注解,提高了开发的灵活性,下面介绍一下最常用的一些注解 @JsonIgnoreProperties此注解是类注解,作用是json序列化时将Java bean ...
-
MFC六大核心机制之三:动态创建
MFC中很多地方都使用了动态创建技术.动态创建就是在程序运行时创建指定类的对象.例如MFC的单文档程序中,文档模板类的对象就动态创建了框架窗口对象.文档对象和视图对象.动态创建技术对于希望了解MFC底 ...
-
SaltStack自动化运维工具
一.SaltStack的了解 SaltStack管理工具允许管理员对多个操作系统创建一个一致的管理系统,包括VMware vSphere环境. SaltStack作用于仆从和主拓扑.SaltStack ...
-
grep和egrep正则表达式
Linux上文本处理三剑客 grep :文本过滤( 模式:pattern) 工具 grep, egrep, fgrep (不支持正则表达式搜索,但搜索纯文本的数据最快) sed :stream edi ...