EF N层架构 [英] EF N-Tier Architecture

查看:149
本文介绍了EF N层架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简介

我们需要建立一个n层应用程序,因为我们想在多个平台来分享我们的BL和只写我们的DAL一次。我已经做了关于这个问题的一些研究。

We require to build a n-tier application, as we would like to share our BL over multiple platforms and only write our DAL once. I've already done some research on this subject.

由于可以在这里达维德Piras酒店的帖子阅读: MVC3和Entity Framework 每个VS解决方案至少必须有4层。到目前为止好。

As can be read here in Davide Piras's post: MVC3 and Entity Framework each VS solution must at least have 4 layers. So far so good.

他还指出,DAL项目是被允许甚至不知道正在使用的EF的唯一项目

He also states that the DAL project is the only project which is allowed to even know that EF is being used.

问1:

我假设,即'接口'项目的接口是我的EF实体的1对1的再presentation,我是正确的呢?此外,这些接口应该被用作不同层之间类型?

I'm assuming, that the interfaces of the 'Interfaces' project are a 1 on 1 representation of my EF entities, am i correct on this? Also, these interfaces should be used as types between the different layers?

问题2:

MSDN 通知:一个的DbContext的寿命应该是一个上下文每对WebApps的请求,并在WPF或WinForms项目每个表单一个上下文。那么,怎样才能我无添加'System.Data.Entity的我的GUI层实现这一目标?

MSDN advices that the lifetime of a DbContext should be one context per request for WebApps, and one context per form in a WPF or WinForms project. So, how can i achieve this without adding 'System.Data.Entity' to my GUI layer?

日Thnx提前!

推荐答案

所有的先不要!!! 分享您的DAL在多个平台上。分享您的BL它采用DAL。只要你的BL重新present解决方案,您不必暴露你的DAL,请不要您的应用需求。也暴露出DAL有更多的暴露给vulnerabiilties黑客和直接存取权限DAL的缺点,提供了一个btpass机制,业务逻辑,控制和验证在你的BL。

First of all DO NOT!!! share your DAL over multiple platform. Share your BL which uses DAL. As long as your BL represent solutions to your application requirements you do not need to expose your DAL and, please don't. Also exposing DAL has the disadvantage of exposing more vulnerabiilties to hackers and direct acces to DAL provides a btpass mechanism to your Business Logic, Controls and Validations in your BL.

答1:
可能但不需要。考虑到与SOA思考,我建议使用的DTO。他们要么是实体或更复杂的,几个和/或部分实体复合类。如果您使用的实体,这给你更多的灵活性,通过BL提供信息(您可以通过一个方法调用一次发送多个数据部分)和第三方用户提供更好的安全意识隐藏YOUE实体(也DB结构)。

Answer 1: Possibly but not need to. Thinking with SOA in mind I suggest to use DTOs. Either they are entities or more complex, composite classes of several and/or partial entities. If you use entities this gives you more flexibility to provide information via BL (you can send several portions of data at once by one method call) and hides youe entity (also DB structure) from third party users providing a better sense of security.

答2:
此外,考虑到与SOA的思维,不要根据自己的用户界面构建你的BL /服务的方法。 BL(顾名思义)根据提供的数据的的工作是如何完成的的不的如何工作是由用户在屏幕上完成的。如果你试图从管理GUI您的数据也将开始违反N层架构。 不要!!! :使用DAL之外的任何数据spesific类和/或方法。这将是真正的利用层次感。

Answer 2: Again, thinking with SOA in mind, do not construct your BL/Service methods according to your User Interface. BL (as the name implies) provides data according to "how the work is done" not "how the work is done by the user on the screen". And if you try to manage your data from GUI you will also start to violate N-tier architecture. DO NOT!!! use any data spesific class and/or methods outside of DAL. This will be the true use of layering.

问候。

这篇关于EF N层架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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