.NET N 层体系结构:我如何处理模型对象? [英] .NET N-Tier Architecture: What do I do about the Model objects?
问题描述
我正在使用 ASP.NET Web 表单 C# 从头开始创建解决方案.
I am creating a solution from scratch, using ASP.NET Web forms C#.
我担心模型对象,因为我不想在每一层中创建重复的模型对象集.在 Web Forms
的 3 层架构中使用 Model 对象的最佳实践是什么?
I am concerned about the model objects as I don't want to create duplicate sets of model objects in each layer. What is the best practice for using Model objects in 3 layer architecture in Web Forms
?
我想到的结构如下:
- 界面
- BLL
- DAL
- 模型
模型将包含可以在层的每个部分中使用的所有模型类.我认为这会很有用,因为每一层都需要访问模型对象.例如:
The Model will contain all the model classes that can be used in each section of the layers. I thought this would be useful as each layer needs access to the model objects. For example:
- UI 调用 BLL 中的方法,传入填充数据的模型对象.
- BLL 通过保存的对象调用 DAL 中的方法在数据库等中
谢谢
推荐答案
看看我的回答:https://stackoverflow.com/a/7474357/559144 这是我做事的常用方式,而且效果很好,不仅适用于 MVC 和实体框架……事实上,在 MVC 中,模型可能是一个只有一些字段的实体类型由下层定义的真实业务实体包含,这取决于您是否真的需要 UI 级别中的所有字段,或者只需要一些字段来进行一些数据渲染和输入...
look at my answer here: https://stackoverflow.com/a/7474357/559144 this is the usual way I do things and works well, not only for MVC and Entity Framework... in fact in MVC the model could be an entity type which only has some of the fields contained by the real business entities defined in lower layers, it depends if you really absolutely need all fields in the UI level as well or only some to do some data rendering and input...
这篇关于.NET N 层体系结构:我如何处理模型对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!