首先在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. 获取URL参数

    function GetQueryString(name){ var reg = new RegExp("(^|&)"+ name +"=([^&]*)( ...

  2. linq简介

    语言集成查询(Language INtegrated Query,LINQ)是一项微软技术,新增一种自然查询的SQL语法到.NET Framework的编程语言中,可支持Visual Basic .N ...

  3. iphone dev 入门实例7:How to Add Splash Screen in Your iOS App

    http://www.appcoda.com/how-to-add-splash-screen-in-your-ios-app/ What’s Splash Screen? For those who ...

  4. 张恭庆编《泛函分析讲义》第二章第5节 共轭空间 $\bullet$ 弱收敛 $\bullet$ 自反空间习题解答

    1.$\ell^p\ (1\leq p<\infty)$ 的对偶 求证: $\dps{\sex{\ell^p}^*=\ell^q\quad\sex{1\leq p<\infty,\ \fr ...

  5. 玄机论坛Socket类库源码 当前版本 2.6.3 更新日期:10-09/2015 z

    http://bbs.msdn5.com/thread-27-1-1.html 本类库采用TcpLister,TcpClient高度封装, 采用NetworkStream进行异步模式读取数据. 采用S ...

  6. Oracle 查看表空间的大小

    SELECT SUM(bytes) / (1024 * 1024) AS free_space, tablespace_name FROM dba_free_space GROUP BY tables ...

  7. [AIR] Screen 的应用

    Screen 类提供此应用程序的可用显示屏幕的相关信息. 屏幕是位于可能更大的“虚拟桌面”内的独立桌面区域.虚拟桌面的原点是操作系统指定的主屏幕的左上角.因此,个别显示屏幕范围的坐标可能是负数.虚拟桌 ...

  8. clone代码

    例子1:

  9. oracle 导入数据

    1.在数据库中建立实例数据库之后,运行cmd 2.键入 imp空格(实例数据库名)/(实例数据库口令)空格file=“拖入数据地址” 比如czt.dmp文件直接拖进去(空格)full=y 3.按ent ...

  10. HappyNum

    /*Write an algorithm to determine if a number is "happy". A happy number is a number defin ...