首先在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. 杀死future处理的阻塞线程

    public class Test{ public static void main(String[] args){ ExecutorService pool = Executors.newFixed ...

  2. (C#) 多线程修改布尔值, volatile

    参考: https://msdn.microsoft.com/en-us/library/x13ttww7(VS.80).aspx http://stackoverflow.com/questions ...

  3. ZOJ 4257 MostPowerful(状压DP,简单)

    题目大意:不超过10种气体,两两之间相互碰撞可以产生一定的能量,如a碰b,那么b气体就消失,自身不能碰自身,问最后所能得到的最大能量. 原代码链接:http://blog.csdn.net/accry ...

  4. 冲突--ScrollView嵌套ListView只显示一行

    在开发的过程当中,由于手机屏幕的大小的限制,我们经常需要使用滑动的方式,来显示更多的内容.在最近的工作中,遇见一个需求,需要将ListView嵌套到ScrollView中显示.于是乎有了如下布局: & ...

  5. Configuration problem: Only one AsyncAnnotationBeanPostProcessor may exist within the context.

    去配置文件中找 , 某个配置文件被引用了两次以上.移除后保留一个即可.如下即可产生上述问题 <import resource="classpath:testContext-curren ...

  6. PHP解析JSON和XML方法

    一.JSON $r = json_decode("json数据"); $result = $r->result; //解析后的数据,以数组形式保存到r里面了,需要通过-> ...

  7. 按钮/文本框 disabled

    需求:已登入的,将用户的信息回填,用户文本框内容不能更改. 按钮: <button type="button" id="btnSearch">< ...

  8. Ubuntu下删除配置错误或者失败的安装包

    aptitude purge $(dpkg -l|grep ^rc|awk '{ print $2 }') 解释:dpkg -l 列出系统中所有安装的软件,如果是已经删除的软件(有残存的配置文件),那 ...

  9. 如何设置BIOS使服务器断电后再来电能自动开机

    不同的主板及CMOS型号相对应的选项会有所不同,但我想应该不会差太多,一般都在[POWER MANAGEMENT SETUP]和[Integrated Peripherals]这两个选项中.下面介绍两 ...

  10. [Java] 通过文件流拷贝文件

    package test.stream; import java.io.FileInputStream; import java.io.FileNotFoundException; import ja ...