简体   繁体   English

不使用实体框架的MVC应用程序架构

[英]Architecture of MVC application without using entity framework

I am new in MVC application development.I am willing to develop a new project using MVC, i looked a lot for architectures that suits to MVC application. 我是MVC应用程序开发的新手。我愿意使用MVC开发一个新项目,对于适合MVC应用程序的体系结构,我看了很多。 After reading many articles and blogs i came to know that repository pattern can be used for this. 阅读了许多文章和博客后,我开始知道可以使用存储库模式。
Based on my understanding before starting real project i created a dummy project structure like described below [ Not using EDMX file, entity framework in project, defined custom DAL ] 根据我在开始实际项目之前的理解,我创建了一个如下所述的虚拟项目结构[不使用EDMX文件,项目中的实体框架,定义的自定义DAL]

Name of my dummy application is Repository.I took Country,state and city relationship as example to develop dummy application : 我的虚拟应用程序的名称为Repository。我以国家,州和城市的关系为例来开发虚拟应用程序:

Repository_DAL_V1 class library This library has class as below : Repository_DAL_V1 类库该库具有以下类:
SQLHelper.cs : This class have methods to get executed for queries like ExecutenonQuery etc. SQLHelper.cs:此类具有为诸如ExecutenonQuery等查询执行的方法。

Repository_DTO_V1 class library This library has class as below : Repository_DTO_V1 类库该库具有以下类:
CountryDTO.cs : This class is inherited from CountryModel.cs as [ CountryDTO:CountryModel ].This will be used to move data between all layers of application.If there is any property that is supposed to be used in business then this will be created in DTO not in model. CountryDTO.cs:此类从CountryModel.cs继承为[CountryDTO:CountryModel]。它将用于在应用程序的所有层之间移动数据。如果有任何应用于业务的属性,则将创建此属性在DTO中未在模型中。
CountryDTOMapper.cs : This is used to map data from database in form of DataTable into collection of DTO object. CountryDTOMapper.cs:用于将来自数据库的数据以DataTable的形式映射到DTO对象的集合中。

Repository_Implementation web mvc project This is UI Layer. Repository_Implementation Web mvc项目这是UI层。

Repository_IRepositories_V1 class library This library has class as below : Repository_IRepositories_V1 类库该库具有以下类:
ICountryRepository.cs : This is a interface having declared functions like SaveCountry() etc. ICountryRepository.cs:这是一个接口,具有已声明的功能,例如SaveCountry()等。

Repository_Models class library This library has class as below : Repository_Models 类库该库具有以下类:
CountryModel.cs : This class has properties exactly for all columns of table in database. CountryModel.cs:此类完全具有数据库中表的所有列的属性。

Repository_Repositories_V1 class library This library has class as below : Repository_Repositories_V1 类库该库具有以下类:
CountryRepository.cs : This is a repository class having defined functions like SaveCountry() etc. CountryRepository.cs:这是一个存储库类,具有已定义的功能,例如SaveCountry()等。

Repository_ViewModel_V1 class library This library has class as below : Repository_ViewModel_V1 类库该库具有以下类:
CountryViewModel.cs : This will be build for Country View on screen. CountryViewModel.cs:这将为屏幕上的“国家/地区视图”构建。

above projects reference details : 以上项目参考资料:

Repository_DTO_V1 has reference of Repository_Models. Repository_DTO_V1具有Repository_Models的引用。
Repository_IRepositories_V1 has reference of Repository_DTO_V1,Repository_Models. Repository_IRepositories_V1具有Repository_DTO_V1,Repository_Models的引用。
Repository_Repositories_V1 has reference of Repository_IRepositories_V1,Repository_DAL_V1,Repository_DTO_V1,Repository_Models. Repository_Repositories_V1引用了Repository_IRepositories_V1,Repository_DAL_V1,Repository_DTO_V1,Repository_Models。
Repository_ViewModel_V1 has reference of Repository_Repositories_V1,Repository_IRepositories_V1,Repository_DTO_V1,Repository_Models. Repository_ViewModel_V1引用了Repository_Repositories_V1,Repository_IRepositories_V1,Repository_DTO_V1,Repository_Models。

I need guidence from all of you to steer me in the right direction. 我需要所有人的指导,以指导我朝正确的方向发展。

I don't se why not using EF would be any different from any other project you done layer wise that is. 我不知道为什么不使用EF与您逐层完成的任何其他项目有什么不同。 There is nothing wrong with you structure of things if you are comftable with using mulitple layers. 如果您对多层结构感到满意,那么您的事物结构就没有错。 I don't know what your project is about but you should consider better naming, like Project name (Repository) and Implementations is better named Web. 我不知道您的项目是关于什么的,但是您应该考虑使用更好的命名方式,例如项目名称(存储库),而“实现”则更好地命名为Web。

EDIT 编辑
I recommend you to use Entity Framework 5 with Code First, that is if you want to use a ORM? 我建议您将Entity Framework 5与Code First一起使用,也就是说,是否要使用ORM?

I'm certainly with you on the desire to give EF a miss. 我当然希望您能错过EF。

As @Dejan.S says, The architecture you'll need depends on the size of your project. 正如@ Dejan.S所说,您需要的体系结构取决于项目的大小。

I would start off simple, perhaps with 3 projects: 我将从简单开始,也许有3个项目:

  • A web project. 一个网络项目。
  • A service project that controllers use to access models and business logic. 控制器用来访问模型和业务逻辑的服务项目。
  • A domain project with your models and data access. 具有模型和数据访问权限的领域项目。

If you need to separate things (like a DAL), you can still do that later. 如果您需要分离事物(例如DAL),则以后仍然可以这样做。

Also, check out ServiceStack's MVC Power Pack . 另外,请查看ServiceStack的MVC Power Pack You get a great micro ORM, IoC, caching, fast serialisers and so on out of the box. 您可以立即获得出色的微型ORM,IoC,缓存,快速序列化程序等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM