首先在github上面将ProDinner项目通过 Git Bash 克隆到本地,接下来我们开始分析这个项目吧~

系统采用.Net 4.5, Asp.net Mvc 5,VS2012,Sql server,系统的整体设计非常轻量级,却做到了整体架构分层明显,模块耦合度低的架构思想,很适合新手学习.

Core层实现了本地化Model和EF模型化需要的model数据,另外,Core层还为低耦合的业务逻辑和低耦合的数据访问做好了接口准备.

1.Model:

以下是表关系的大致内容:

我们在分析数据库表结构的时候,经常会发现表与表之间有很多共同的字段,例如Id,操作时间,操作人等等,所以可以为这些表构造公共基类,比如Entity就是所有表的基类.而事实上,对First Code而言,根本就不存在数据库的概念.

 public class Entity
{
public int Id { get; set; }
} public class Feedback : Entity
{
public string Comments { get; set; }
} public class Meal : DelEntity
{
public string Name { get; set; }
public string Comments { get; set; }
public virtual ICollection<Dinner> Dinners { get; set; }
public string Picture { get; set; }
} public class Role : Entity
{
public string Name { get; set; }
public virtual ICollection<User> Users { get; set; }
} public class User : DelEntity
{
public string Login { get; set; }
public string Password { get; set; }
public virtual ICollection<Role> Roles { get; set; }
} public class Dinner : DelEntity
{
public string Name { get; set; }
public int CountryId { get; set; }
public virtual Country Country { get; set; }
public int ChefId { get; set; }
public virtual Chef Chef { get; set; }
public string Address { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
public virtual ICollection<Meal> Meals { get; set; }
} public class DelEntity : Entity, IDel
{
public bool IsDeleted { get; set; }
} public class Country : DelEntity
{
public string Name { get; set; }
} public class Chef : DelEntity
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int CountryId { get; set; }
public virtual Country Country { get; set; }
} public interface IDel
{
bool IsDeleted { get; set; }
}

从代码中可以看出,涉及到表关联的时候,统一使用了ICollection<T>的集合,类型都是Virtual,这表明这一Model层都是接口和基类,会被重写.

接下来就是创建应用程序所需的业务类.

2.Repository(仓库)

 public interface IDelRepo<T>
{
IQueryable<T> Where(Expression<Func<T, bool>> predicate, bool showDeleted = false);
IQueryable<T> GetAll();
void Restore(T o);
}
public interface IRepo<T>
{
T Get(int id);
IQueryable<T> GetAll();
IQueryable<T> Where(Expression<Func<T, bool>> predicate, bool showDeleted = false);
T Insert(T o);
void Save();
void Delete(T o);
void Restore(T o);
}
public interface IUniRepo
{
T Insert<T>(T o) where T : Entity, new();
void Save();
T Get<T>(int id) where T : Entity;
IEnumerable<T> GetAll<T>() where T : Entity; }

从代码可以很明显看出,这是数据操作方式和数据业务逻辑的函数原型,其后service的所有具体实现的实体数据操作都会基于这些接口.

3.Security

引用了Asp.net的身份验证模块,故也进行了相应的接口限制

    public interface IFormsAuthentication
{
void SignIn(string userName, bool createPersistentCookie, IEnumerable<string> roles);
void SignOut();
}

4.Service

该层接口详细定义了四个类的操作接口:

ICrudService继承了上层接口的抽象接口

IMealService类继承了 ICrudService 同时,规定了图片保存的接口

IUserService继承了ICrudService,规定了用户验证的接口

5.ProDinnerException规定了系统自定义的抛错机制。

至此,Core层就介绍完了~

ASP.NET MVC 开源项目学习之ProDinner (一)的更多相关文章

  1. ASP.NET MVC 开源项目学习之ProDinner (二)

    下面我们来看第二层:Data   这一层相对来说是对Core层的具体实现了. 从命名可以看出来,这和数据库相关. 1.Db.cs CodeFirst模式的本地数据库类,继承了DbContext. pr ...

  2. ASP.NET MVC 开源项目学习之ProDinner (三)

    第四层:Resources   这一层里面主要是几个资源文件. 资源文件知识小杂烩: 几乎每一个生产性应用程序都需要使用资源.资源是在逻辑上由应用程序部署的任何非可执行数据.资源可以在应用程序中作为错 ...

  3. ASP.Net MVC开发基础学习笔记:一、走向MVC模式

    一.ASP.Net的两种开发模式 1.1 ASP.Net WebForm的开发模式 (1)处理流程 在传统的WebForm模式下,我们请求一个例如http://www.aspnetmvc.com/bl ...

  4. ASP.Net MVC开发基础学习笔记(1):走向MVC模式

    一.ASP.Net的两种开发模式 1.1 ASP.Net WebForm的开发模式 (1)处理流程 在传统的WebForm模式下,我们请求一个例如http://www.aspnetmvc.com/bl ...

  5. ASP.NET MVC Web API 学习笔记---第一个Web API程序

    http://www.cnblogs.com/qingyuan/archive/2012/10/12/2720824.html GetListAll /api/Contact GetListBySex ...

  6. angular2+typescript在asp.net MVC Web项目上的实现

    网上现在还没有关于angular2+typescript在asp.net mvc web项目上的实现的系统介绍,这里我也只是探索到了一个简单的方式,还有很多问题没能解决.但是能有个好的开头也值得记录一 ...

  7. 使用Visual Studio 2015 开发ASP.NET MVC 5 项目部署到Mono/Jexus

    最新的Mono 4.4已经支持运行asp.net mvc5项目,有的同学听了这句话就兴高采烈的拿起Visual Studio 2015创建了一个mvc 5的项目,然后部署到Mono上,浏览下发现一堆错 ...

  8. ASP.NET MVC搭建项目后台UI框架—1、后台主框架

    目录 ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NET MVC搭建项目后台UI框架—3.面板折叠和展开 ASP.NE ...

  9. ASP.NET MVC搭建项目后台UI框架—11、自动加载下拉框查询

    ASP.NET MVC搭建项目后台UI框架—1.后台主框架 需求:在查询记录的时候,输入第一个字,就自动把以这个字开头的相关记录查找出来,输入2个字就过滤以这两个子开头的记录,依次类推. 突然要用到这 ...

随机推荐

  1. 黄聪:WebBrowser执行和安装jQuery脚本(IEBrowse)

    上一文章说明了如何让 js 脚本访问 .NET 中的类, 这次希望给大家说明一下在任意页面中安装 jQuery 脚本, 并操作页面上的元素. 其实在第一篇关于 IEBrowser 的文章当中, 已经有 ...

  2. 在指定路径下查找并打印mdb类型文件

    1 #encoding:utf8 import os fpath = 'D:\Download\LP传奇-麒麟传说\Date' rfile = '' files = [] mdbFiles = [] ...

  3. jetty-run运行报错的原因

  4. PLSQL_长脚本如何判断需耗时多久v.sql / v.sqltext / v.sqlarea / v.sql_plan及nohup(案例)

    2014-08-27 Created By BaoXinjian

  5. HTML 表单验证和事件

    1.表单验证<form></form> (1).非空验证(去空格) (2).对比验证(跟一个值对比) (3).范围验证(根据一个范围进行判断) (4).固定格式验证:电话号码, ...

  6. Java语法基础动手动脑实践

    输出结果为: 0.05+0.01=0.0600000000000000051.0-0.42=0.58000000000000014.015*100401.49999999999994123.3/100 ...

  7. 【weiphp微信开发教程】留言板插件开发详解

    基于weiphp框架的留言板插件教程: 1.功能分析 传统的留言板应该具有发布留言.查看留言.回复留言.管理留言等功能,本教程开发的是最基本的留言板,仅包含发布留言和查看留言两个功能,根据功能用boo ...

  8. 并发容器之ConcurrentSkipListSet

    概要 本章对Java.util.concurrent包中的ConcurrentSkipListSet类进行详细的介绍.内容包括:ConcurrentSkipListSet介绍ConcurrentSki ...

  9. Python补充01 序列的方法

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在快速教程中,我们了解了最基本的序列(sequence).回忆一下,序列包含有定值 ...

  10. IronPython调用C# DLL函数方法

    C# DLL源码 using System; using System.Collections.Generic; using System.Text; using System.Security.Cr ...