使用 WPF 和 WPF 的业务应用程序的最佳架构是什么? EF?
我对我们可以用来使用 WPF 4.0 和 EF 4.0 技术开发业务应用程序的架构感到困惑。
我的第一选择是传统的 N 层架构,包含:UI、业务逻辑层和应用程序层。具有断开连接行为的数据访问层。
通过这种方式,我为每层创建 3 个项目,并为我的实体/DTO 创建另一个项目(每层都是一个程序集)。每层仅引用其上层和下层(即:UI 可以看到 BLL,但看不到 DAL)。但出于通信目的,所有层都可以访问实体/DTO 程序集。 例如,当我想使用 DataGrid 创建一个简单的 CRUD 表单时,问题就开始了。当返回Entity/DTO时,BLL会处理DAL的DataContext,这就是迫使我使用STE的原因。但仍然存在几个问题。例如,我应该为从 BLL 返回到 UI 的每个实体调用“StartTracking”方法。简而言之,我不确定这种模式的可靠性,或者我认为我必须忘记自动处理的 CRUD 表单。
我在 DAL 层中使用存储库模型,但是当我搜索存储库模式时,我发现它有所不同。看起来,从 UI 引用 DAL/Repository 和 BLL/Services(不是 WCF 或 WebServices)层也不错,因此我们可以拥有一个连接的环境(不使用 STE)。
我看到一个例子,我们可以从存储库中获取一个人,但使用 BLL 或服务对其执行某些操作:
UI 代码:
var person = new PersonRepository().GetPerson(10);
Bll.Salary.PaySalary(person);
- 或
var person = new PersonRepository().GetPerson(10);
Bll.Person.MarkAsAbsent(person);
- 或类似的东西...
使用这种模式,我们可以将实体/DTO 发送到 UI DataContext 处于活动状态时的连接方式。
不知道我是否理解在大型项目中使用存储库模式的方式。我认为以这种方式命名 BLL 或服务类和方法并不清楚。更重要的是,开发人员可能会对在哪里使用存储库方法或 BLL/服务方法或在哪里创建方法(在存储库或 BLL/服务中)感到困惑。
我更喜欢 N 层架构,它使用一种很好的方法来像 STE 一样自动跟踪实体/DTO 的更改。
请您推荐在这种情况下的最佳模式或/并给我参考一些关于这方面的好书或文档。
I'm confused about the architectures which we can use to develop a business application with WPF 4.0 and EF 4.0 technologies.
My first choice was a traditional N-tier architecture contains: UI, Business Logic Layer & Data Access Layer with a disconnected behavior.
In this way I create 3 project for each layer and another project for my Entities/DTOs (Each layer is an assembly). Each layer references only to it's upper and lower layers (That is: UI can see the BLL but can't see the DAL). But all layers have access to the Entity/DTOs assembly for communication purposes.
The problem starts when I want to create a simple CRUD form with a DataGrid for example. The BLL disposes the DataContext of the DAL when returns an Entity/DTO, this is the reason that forced me to use STEs. But yet there are several problems. For example I should call "StartTracking" method for each entity returned from BLL to the UI. In short, I don't sure about this pattern reliability or I think I have to forget about automatic handled CRUD forms.
I use the repository model in my DAL layer but when I search about the repository pattern I find it different. It seems that it's not bad to reference to both of the DAL/Repository and the BLL/Services(Not WCF nor WebServices) layers from the UI and thus we can have a connected environment (Without using STEs).
I see an example in which we can get a person from repository but do something on it using BLL or services:
UI CODE:
var person = new PersonRepository().GetPerson(10);
Bll.Salary.PaySalary(person);
-or-
var person = new PersonRepository().GetPerson(10);
Bll.Person.MarkAsAbsent(person);
Or something like that...
With this pattern we can send the Entities/DTOs to the UI in a connected way while the DataContext is alive.
I don't know if I understand the way of using the repository pattern in big projects. I think it's not clear to naming the BLL or services classes and methods in this way. More over the developers might be confused about where to use the repository methods or BLL/service methods or about where to create the methods (in repositories or BLL/service).
I prefer the N-Tier architecture using a good approach to track the Entities/DTOs changes automatically like STEs.
Would you please recommend the best pattern in such situations or/and reference me to some good books or documents about that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我整理了一个示例应用程序,可能有助于解决您的一些问题。您可以通过我的博客文章查看演示文稿说明和示例:
http://blog.alner.net/archive/0001/01/01/wpf_ef_4_sig_presentation_2010.aspx
该示例展示了如何使用 STE,并包含一些帮助程序,以使实体框架 STE 在桌面客户端应用程序。
存储库用于隐藏如何获取数据的详细信息。这个想法是,您可以将存储库的实现从使用本地数据库的存储库的实现交换为使用远程 Web 服务的存储库的实现,而上层不知道这一点。
I put together a sample app that may help with some of your questions. You can review the presentation notes and the sample via my blog post here:
http://blog.alner.net/archive/0001/01/01/wpf_ef_4_sig_presentation_2010.aspx
The sample shows using STEs and includes some helpers to make the Entity Framework STEs work better in a desktop client app.
Repositories are there to hide the details of how you get the data. The idea is that you could swap the implementation of a repository from one that uses a local database, to one that uses a remote web service without the upper layers knowing about it.
也许这篇文章 Architecture for WPF 应用程序 可以为您提供任何帮助。
您可以查看 WPF 应用程序框架 (WAF) 的 BookLibrary 示例应用程序以及。它展示了 WPF MVVM 应用程序以及应用所描述架构的实体框架。
Maybe the article Architecture for WPF applications is any help for you.
You might have a look at the BookLibrary sample application of the WPF Application Framework (WAF) as well. It shows a WPF MVVM application together with the Entity Framework applying the described architecture.