在六边形架构中动态加载适配器的最佳方式?

Best way to dynamically load adapters in hexagonal architecture?

我想在我的 userManagement boundedContext 中应用六边形架构。所以我想定义 2 个端口(一个用于 UI,另一个用于 serviceBus 集成,以侦听来自其他服务的事件)。

问题是我是否想为 UI port 实现 adapters(我不确定它应该被称为 UI port,基本上就是 CreateNewUser, BlockUser, CheckIfUserExists 的接口实时操作)使用不同的技术 WCFOwin。如何将它们添加到我的控制台应用程序?

假设我想使用 WCF 实现 Soap adapter,其余使用 Owin。在许多示例中,我看到人们为每个驱动适配器创建单独的控制台应用程序,即:MyDDD.UserManagement.Api.Rest.HostMyDDD.UserManagement.Api.Soap.Host。我想要实现的是一个主机应用程序以及以某种方式将适配器连接到它的能力。请分享您的想法!

So I want to define 2 ports (one for UI, another one for serviceBus integration, to listen for events from another services).

你误解了端口的概念。你所说的 UI 和服务总线集成是适配器。它们是端口的 2 个适配器。他们使用端口。他们调用端口提供的操作。该端口与技术无关,独立于交付机制。该端口只是一个提供应用程序用例的接口。

UI port(I'm not sure it should be called UI port, basically that's the interfaces where CreateNewUser, BlockUser, CheckIfUserExists operations live)

端口应根据其用途命名。如果操作是为了管理用户,我应该称之为"userManagement"。或者,如果您的 BC 以这种方式命名,则只需调用端口 "api"(不过我更喜欢有意义的名称)。

if I want to implement adapters... How can I add them to my console app?

我认为你错了。如果控制台是指 CLI,那么控制台就是端口的另一个适配器。您不向其添加适配器。

if I want to implement adapters for UI port using different technologies WCF and Owin. How can I add them to my console app?

我告诉你我的做法:适配器用名称声明自己(带有自定义注释)。主要组件在引导整个系统时扫描适配器,并通过检查它们的名称select 为每个端口扫描您想要的适配器。

What I want to achieve is one host app and the ability to connect adapters to it somehow.

我是这样做的:我有一个多模块项目。六边形是一个模块,每个适配器都是另一个模块。我有另一个名为 "main" 的模块,它一起构建并运行您想要的适配器。例如,您可以将每个端口所需的适配器放在属性文件中。我就是这样做的。