使用 WCF 的 DDD 项目结构 [英] DDD Projects Structure With WCF

查看:32
本文介绍了使用 WCF 的 DDD 项目结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在启动一个新的基于 WCF 的项目,该项目由一个引擎"和一些桌面应用程序组成.但是我发现我的项目结构很难构建.

I'm starting a new WCF-based project which is composed by an "Engine" and some desktop applications. But i found it difficult to make my project structure.

  • 引擎(Windows 服务,它托管用于桌面应用程序访问和托管我所有业务逻辑的 WCF 服务)
  • 桌面应用程序(仅演示)

  • Engine (Windows Service, which host WCF Services for Desktop applications access and host all my business logic)
  • Desktop Application (Only Presentation)

共享

MyProject.Core(客户/客户、客户/ICustomerService)

MyProject.Core (Customers/Customer, Customers/ICustomerService)

引擎

  • MyProject.Engine(Customers/CustomerService、Customers/ICustomer、Customers/ICustomerRepository)
  • MyProject.Infrastructure.SqlServer(客户/客户(LinqToSql 特定)、客户/CustomerRepository)

WinForm 应用程序

我说得对吗?

推荐答案

如果你在做 DDD,我觉得很奇怪你没有域模型.你有一个所谓的引擎,它有多个问题.它实现您的业务逻辑,并了解将您的业务逻辑作为 Windows 服务托管.

If you are doing DDD I find it strange that you have no domain model. You have a so-called engine, which has multiple concerns. It implements your business logic and knows about hosting your business logic as a windows service.

我建议的项目结构如下:

I would propose a project structure as follows:

MyProject.Model:定义抽象存储库、实体、值对象、服务(DDD 术语)和其他域逻辑.它没有对其他项目的引用

MyProject.Model: Defines abstract repositories, entities, value objects, services (DDD term) and other domain logic. It has no references to other projects

MyProject.DataAccess:使用 linq2sql 实现存储库.引用了 MyProject.Model

MyProject.DataAccess: implementation of repositories using linq2sql. Has a reference to MyProject.Model

MyProject.ServiceModel:包含服务合同和其他将域模型公开为 WCF 服务的相关内容.该项目还将包含服务所服务和接受的域对象的服务特定表示.这样做的原因是您可能不应该使用 WCF 数据协定中所需的属性来装饰域类.该项目引用了 MyProject.Model.

MyProject.ServiceModel: Contains service contracts and other stuff related exposing your domain model as WCF services. this project would also contain service specific representations of those of your domain objects that the service serves and accepts. The reason for this would be that you should probably not decorate your domain classes with the attributes needed in WCF data contracts. This project references MyProject.Model.

MyProject.Service:包含您的服务的 app.config,并通过自定义 ServiceHost 和 ServiceHostFactory 执行依赖项注入.它引用了 MyProject.Model MyProject.ServiceModel 和 MyProject.DataAccess + 你最喜欢的 DI 框架(例如 Windsor Castle)

MyProject.Service: Contains app.config for your service and performs dependency injection, through a custom ServiceHost and ServiceHostFactory. It references MyProject.Model MyProject.ServiceModel and MyProject.DataAccess + your favorite DI framework (Windsor Castle for example)

MyProject.PresentationModel:定义在您的 UI 中使用的各种视图模型和命令.它具有对 MyProject.Service 公开的服务的服务引用

MyProject.PresentationModel: Defines various view models and commands to use in your UI. It has service references to the services exposed by MyProject.Service

MyProject.WinUI:您的 WPF 应用.参考 MyProject.PresentationModel.

MyProject.WinUI: Your WPF app. References MyProject.PresentationModel.

请注意,您可能在 Eric Evans 的关于 DDD 的书中读到的大部分内容仅与 MyProject.Model 的内容有关.其他项目正在构成先生中未直接涉及的附加层.埃文斯的书.

Note that most of what you have probably read in Eric Evans' book about DDD is only concerned with the contents of MyProject.Model. The other projects are making up additional layers not directly addressed in mr. Evans' book.

请记住,通过明确的关注点分离并使用依赖注入,您最终会得到易于测试的代码.使用我上面提出的结构,您应该能够测试几乎所有内容,因为您的 UI 将只包含 XAML.

Remember that by having a clear separation of concerns, and using dependency injection you will end up with code that is easily tested. With the structure I have proposed above, you should be able to test almost everything, since your UI will contain only XAML.

无论如何,这只是我的看法.如果其中一些需要澄清,请随时询问.

Anyway, this is just my take on it. Please feel free to ask if some of this needs clarification.

祝项目顺利.

/克劳斯

这篇关于使用 WCF 的 DDD 项目结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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