0

I want to apply hexagonal architecture to my userManagement boundedContext. So I want to define 2 ports (one for UI, another one for serviceBus integration, to listen for events from another services).

The question is if I want to implement adapters for UI port(I'm not sure it should be called UI port, basically that's the interfaces where CreateNewUser, BlockUser, CheckIfUserExists operations live) using different technologies WCF and Owin. How can I add them to my console app?

Let's say I want to implement Soap adapter using WCF and rest using Owin. In many examples I see that people create separate console applications per driving adapters, ie: MyDDD.UserManagement.Api.Rest.Host and MyDDD.UserManagement.Api.Soap.Host. What I want to achieve is one host app and the ability to connect adapters to it somehow. Please share your ideas!

Hmax
  • 315
  • 6
  • 16
DmitriBodiu
  • 887
  • 6
  • 19
  • do you want to use both of them or are the substitute each other? – dom May 24 '18 at 08:26
  • I need both of them. – DmitriBodiu May 24 '18 at 13:16
  • i deleted the answer, try to deliver a better one ;) what do you mean with console app? as i understand your request you wanna have one application which has a UI and a service bus and both of them should use the same application service right? – dom May 24 '18 at 13:44
  • By consoleAppication I mean project type in .NET. i.e ClassLibrary, or ConsoleApplicaion (executable). Yes, I want to have one service which has one UI port (not UI client application). Now, there is one team which develops a web client application and they need a rest api to communicate with my service. And there is another team which creates a WPF application, but they want to use WCF (Soap) to communicate with my service. So Iwant to expose 2 adapters from my service. They both will call my Application layer. And I want this configurable if possible. dinamically add or remove this adapters – DmitriBodiu May 24 '18 at 13:52
  • 2
    got it. is there a reason why you wanna add / remove these implementations dynamically? architectural constraint? i don't see any big advantage to do this. more likely to add more unnecessary complexity. – dom May 24 '18 at 14:04
  • Agree, there is no big advantage in it. Its would be nice, but it is not my main goal) – DmitriBodiu May 24 '18 at 14:35
  • @DmitriBodiu It's really unclear what you're asking. If it's not your main goal then what is your main goal? Are you really asking about how to have two adapters for the same port? I don't see what's so hard about having 2 adapters sit alongisde each other. – guillaume31 May 30 '18 at 12:05
  • Could you please share your thoughts how a rest adapter using Owin can live together with soap adapter (WCF)? Should I create an abstraction over adapters so when I connect them to my host, the host will call start() on adapter, and each adapter will implement it apropriately? (Rest adapter will do Owin.Start() and soap adapter will do new ServiceHost().Run()). ? – DmitriBodiu May 30 '18 at 12:29

1 Answers1

1

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

You missunderstood the concept of port. What you call UI and service bus integration are adapters. They are 2 adapters for the port. They use the port. They call the operations offered by the port. The port is technology agnostic, independent from the delivery mechanism. The port is just an interface offering the use cases of your application.

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

Ports should be named according to their purpose. If the operations are for managing users, I should call it "userManagement". Or if your BC is named that way, call the port just "api" (I prefer a meaningfull name though).

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

I think you are wrong here. If by console you mean a CLI, then the console is another adapter for the port. You don't add adapters to it.

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

I tell you the way I do it: Adapters declare themselves with a name (with a custom annotation). The main component, when bootstraping the whole system, scans for adapters, and select the ones you want for each port by checking their names.

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

I do it this way: I have a multi-module project. The hexagon is one module, and every adapter is another module. I have another module named "main" that builds all together and runs the adapters you want. You can put the adapters you want for each port in a properties file for example. That's the way I do it.

choquero70
  • 3,332
  • 2
  • 24
  • 40
  • "I think you are wrong here. If by console you mean a CLI, then the console is another adapter for the port. You don't add adapters to it." - you misunderstood me here. I meant how can I add adapters to my main exe process(console app). – DmitriBodiu Jun 01 '18 at 07:37
  • "I do it this way: I have a multi-module project. The hexagon is one module, and every adapter is another module. I have another module named "main" that builds all together and runs the adapters you want. You can put the adapters you want for each port in a properties file for example. That's the way I do it." - this is exactly what I was looking for) Do you know any existing open source projects, where I can see an example of such functionality? – DmitriBodiu Jun 01 '18 at 07:39
  • https://www.google.com/search?q=hexagonal+architecture&rlz=1C1CHZL_enMD734MD734&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjyj9Sw-7HbAhVJyaYKHeo2BOAQ_AUICigB&biw=1920&bih=900#imgrc=sQcPo-8EDmxezM: Please check out this image. There is an example of hexagonal architecture where 5 ports are defined: and one of them is Messaging queue port. But you say, that this should be an adapter, which will call my "userManagement" port - right? – DmitriBodiu Jun 01 '18 at 07:43
  • @DmitriBodiu Hello, sorry for misunderstand you when you said "console". "Do you know any existing open source projects, where I can see an example of such functionality?" I'm gonna publish my code in github, but didn't finish it yet. Don't know if there exist any other similar project over there ( I guess so, but don't know any). – choquero70 Jun 01 '18 at 09:43
  • @DmitriBodiu "Please check out this image...5 ports are defined: and one of them is Messaging queue port" I don't agree with that picture. I should name the port "notification" or something like that. Message Queue is how the port is implemented (the adapter). Anyway that is a driven port (for sending/publishing events). Your message queue adapter would be a driver adapter (for receiving/listening events). The driver adapter would listen for an incoming event and convert it to a call to the userManagement port. – choquero70 Jun 01 '18 at 10:02
  • @DmitriBodiu "Please check out this image...5 ports are defined". I don't agree with the picture neither when it says that "web services" is a driver port. Web services are adapters (delivery mechanism). The port would be the interfaces offered by the app, and you call it either from a web service adapter, a web app, a message queue adapter, a test adapter, or whatever. – choquero70 Jun 01 '18 at 10:03
  • could you please provide an example (source code) of such modular system? – DmitriBodiu Aug 20 '18 at 13:44
  • 1
    I will upload an example to github. But didint fimished it yet. It's hexagonal architecture using Java 9 modules – choquero70 Aug 22 '18 at 20:33