在域驱动设计中使用包装类使用外部系统的 api

发布于 2024-10-31 04:40:07 字数 221 浏览 6 评论 0原文

有时,如果你想使用 facebook 或 twitter 的 api,你必须使用第三方的服务。然后我们必须创建各种包装类,使用所需的参数调用外部 api 的函数并返回所需的结果。

我的问题是将该包装类放在哪里,在应用程序层本身中并创建一个调用包装类函数的服务类或在基础设施层的单独类库中?

我是否将包装类放在 INFRA LAYER 或 APP LAYER 中?

Sometimes it happens that you have to consume services from third party, if you want to use api of facebook or twitter. Then we have to create various wrapper classes which calls functions of external api with required parameters and return the required result.

My question is where to put this wrapper classes, in App Layer itself and create a service class which call functions of wrapper classes or in separate class library in Infrastructure layer ?

Do I put wrapper classes in INFRA LAYER or in APP LAYER ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残疾 2024-11-07 04:40:07

您在这里本质上想做的是编写一个反腐败层。换句话说,你正在努力保护你的内在领域免受外部影响。

有很多方法可以做到这一点,但本质上最重要的是保持域的完整性。我们要做的就是定义一个“契约”(即接口)来定义您的域对象的一般含义。该接口在您的域中随处使用。

然后你就有了反腐败层代码(即你提到的包装类)。我们将这些包装类保存在名为WhateverPrefix.AntiCorruptionLayer 的程序集中。包装器实现域中定义的“契约”。该域不引用反腐败层组件,但反腐败层组件引用该域。

在反腐败层组件本身中,我们通常会在每个反腐败层的根目录中专门指定一个特定的描述性文件夹。

这些东西不是一门精确的科学,我只是概述了我在我的经验中看到的做这些东西的一种方法。希望这有帮助...

What you are essentially trying to do here is write an anti-corruption layer. In other words you are trying to protect your inner domain from external influences.

There are many ways to do this but essentially you most keep your domain integral. What we would do is define a "contract" (i.e. interface) that defines what your domain object is generically. This interface is what is used everywhere in your domain.

Then you have anti-corruption layer code (i.e. the wrapper classes that you mention). We keep these wrapper classes in an assembly called WhateverPrefix.AntiCorruptionLayer. The wrappers implement the "contract" defined in the domain. The domain does not reference the anti-corruption layer assembly, however the anti-corruption layer assembly does reference the domain.

In the anti-corruption layer assembly itself, we would usually dedicate a specific descriptive folder at its root per anti-corruption layer.

This stuff is not an exact science, Im just outlining one of the ways I have seen this stuff being done in my experience. Hope this helps...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文