干净的解决方案(项目)结构EF,存储库,实体 [英] Clean solution (project) structure with EF, Repositories, Entities

查看:147
本文介绍了干净的解决方案(项目)结构EF,存储库,实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保持这个项目的结构尽可能干净。
示例:

   -  BlogApp.sln
  --BlogApp.Data
      BlogModel.edmx(外汇基金映射)
      Post.cs(我结束了在有部分类在这里与属性)
  --BlogApp.Domain
    --Entities
        Post.cs(我想在这里有我的波苏斯与所有额外的逻辑)
    --Repositories
        PostsRepository.cs
  --BlogApp.Ui
      (标准的MVC结构)

我使用EF作为我的ORM的时候结束了混乱。任何人可以提出一些干净的方式来构建这个项目?或者,也许你会认为是最常用的一些标准的项目结构。


解决方案

我的preferred结构是:


 解决方案
   - 通用
        - 翻过所有层使用的共享功能
        - 您也可以将接口库和UOW这里
   - 实体 - (小型项目和UI)的数据访问,业务之间共享
        - T4模板+局部类+自定义枚举
        - 部分类可以包含域逻辑= GT的方法;域对象
   - 数据访问 - 所有的EF依赖code在这里
        - EDMX或code第一个映射
        - 库
        - 的UnitOfWork
   - 商务 - 并不是每个项目都需要本次大会
       - 商业服务
        - 逻辑样的工作流程
        - DTO的接触到UI
   - 用户界面
        - 控制器
        - 视图
        - 的ViewModels


I like to keep the structure of the project as clean as possible. Sample:

--BlogApp.sln
  --BlogApp.Data
      BlogModel.edmx (the EF mappings)
      Post.cs (I end up having partial classes in here with attributes)
  --BlogApp.Domain
    --Entities
        Post.cs (I would like to have my POCOs here with all its additional logic)
    --Repositories
        PostsRepository.cs
  --BlogApp.Ui
      (standard MVC structure)

I end up with mess when using EF as my ORM. Could anybody suggest some "clean" way to structure the project? Or maybe you could suggest some standard project structure that is most commonly used.

解决方案

My preferred structure is:

Solution
  -- Common
       - Shared features used accross all layers
       - You can also place interfaces for repositories and uow here
  -- Entities - shared among DataAccess, Business (and UI in small projects)
       - T4 template + partial classes + custom enums  
       - partial classes can contain methods with domain logic => domain objects 
  -- DataAccess - all EF dependent code here
       - EDMX or code first mapping
       - Repositories
       - UnitOfWork
  -- Business - not every project needs this assembly
       - Business services 
       - Logic like workflows
       - DTOs exposed to UI
  -- UI
       - Controllers
       - Views
       - ViewModels

这篇关于干净的解决方案(项目)结构EF,存储库,实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆