gpt4 book ai didi

wcf - 服务层中的域逻辑——如何最好地引用它以及公开它

转载 作者:行者123 更新时间:2023-12-02 04:58:45 25 4
gpt4 key购买 nike

我正在设计一个企业解决方案,该解决方案由产品范围内的模块化产品组成,首先使用实体​​框架代码来定义域模型并提供数据访问。

例如解决方案:

ProductRange.Authentication
ProductRange.Gateway
ProductRange.OrderSystem
ProductRange.MarketingSystem

这些产品(解决方案)中的每一个都将具有相似的层,目前:

每个解决方案中的项目:

ProductRange.OrderSystem.Model (contains code first POCOs)
ProductRange.OrderSystem.DataContext (contains the dbContext)
ProductRange.OrderSystem.DataAccess (contains the Generic Repository)
ProductRange.OrderSystem.Service.DomainLogic (contains business logic)
ProductRange.OrderSystem.Service.ApplicationLogic (contains application logic)
ProductRange.OrderSystem.Presentation.AdminWebsite
ProductRange.OrderSystem.Presentation.CustomerWebsite

一些产品需要访问另一个产品的域逻辑,特别是它们都需要访问 ProductRange.Authentication,而且 ProductRange.MarketingSystem 需要查询 ProductRange.OrderSystem

我正在考虑通过 WCF 服务公开范围内产品之间的域逻辑。但我还需要在本地引用产品(例如创建项目引用)。

我应该如何着手实现它?我应该创建一个 WCF 服务吗? ProductRange.OrderSystem.WCF 调用域逻辑并将其公开,或者我的域逻辑本身应该是 WCF 服务吗?如果是后者,我是否总是必须通过 WCF 引用我的域逻辑,甚至是从本地 ApplicationLogic?

我想我正在寻找一些关于应该有哪些层以及如何最好地提供解决方案之间的互连的指导。

最佳答案

您可以使用单个(或多个)层将您的 pocos 公开为数据契约(Contract)和服务契约(Contract)。

例如:

ProductRange.Server.DataContracts
Product
AuthenticationInfo

ProductRange.Server.ServiceContracts
IOrderService
IAuthentication
Auth(AuthenticationInfo info):AuthenticationResult

ProductRange.Server.Services
OrderService
AuthenticationService(implements IAuthentication interface)

在客户端,您可以引用此项目(仅数据契约(Contract)和服务契约(Contract))并通过以下接口(interface)创建透明代理:

var serviceProxy = SomeHelper.CreateServiceProxy<IAuthenticationService>();
var result = serviceProxy.Auth(new AuthenticationInfo());

此外:您可以将 poco 类用作数据契约。如果您想要更好的连接性,那么您可以根据您的要求选择一个绑定(bind)(如 net.tcp)。

关于wcf - 服务层中的域逻辑——如何最好地引用它以及公开它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19002807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com