Presentation on how here at Coolblue we refactored an existing application from a layered architecture to ports & adapters and the benefits we achived by doing so.
26. Reference Direction vs Control Direction
Presentation
Layer
Data Access
Layer
Business Logic
Layer
Reference DirectionControl Direction
27. Ports & Adapters Introduction
Allow an application to equally be driven by users, programs, automated test
or batch scripts, and to be developed and tested in isolation from its eventual
run-time devices and databases.
36. Hexagonal - Domain
Domain
Web API
Message
Service
Scheduler
Persistence
Adapter
Command
Adapter
Notification
Adapter
37. Hexagonal - Persistence Port
Domain
Web API
Message
Service
Scheduler
Persistence
Adapter
Command
Adapter
Notification
Adapter
Persistence
Port
38. Hexagonal - Command Port
Domain
Web API
Message
Service
Scheduler
Persistence
Adapter
Command
Adapter
Notification
Adapter
Persistence
Port
CommandPort
39. Hexagonal - Notification Port
Domain
Web API
Message
Service
Scheduler
Persistence
Adapter
Command
Adapter
Notification
Adapter
Persistence
Port
CommandPort
Notification
Port
40. Hosts Are Types of Adapters
Web Service
Test Harness
Command
Line
Daemon
Windows
Service
Graphical UI
41. Hexagonal - Host Port
Domain
Web API
Message
Service
Scheduler
Persistence
Adapter
Command
Adapter
Notification
Adapter
Persistence
Port
CommandPort
Notification
Port
Host Port
42. Advantages - Domain Testability
Domain
Web API
Message
Service
Scheduler
Persistence
Adapter
Command
Adapter
Notification
Adapter
Persistence
Port
CommandPort
Notification
Port
Host Port
43. Advantages - Boundaries
Web API
Message
Service
Scheduler
Domain
Persistence
Adapter
Command
Adapter
Notification
Adapter
44. Advantages - Alternative Adapters
Domain
Web API
Message
Service
Scheduler
Persistence.Adapter Command.Adapter
Notification
Adapter
Persistence
Port
CommandPort
Notification
Port
Host Port
Persistence.Adapter
Csv
Command.Adapter
File
45. Notification via SMTP
Domain
Web API
Message
Service
Scheduler
Persistence
Adapter
Command
Adapter
Notification
Adapter
Persistence
Port
CommandPort
Notification
Port
Host Port
47. Book Ordering Service - Client 1
● REST endpoints for adding books,
approving and submitting
● Notification to supplier to be via SMTP
● Persistence to MySQL
48. Book Ordering Service - Client 2
● RabbitMq message for adding books
● REST endpoints for adding approving and
submitting
● Notification to supplier to be via
RabbitMq message
● Persistence to MySQL
49. Book Ordering Service - Architecture
Domain
Host
Web API
Client 1
Web API
Client 2
Persistence
MySQL
Notification
SMTPRabbitMq
CommandRabbitMq
51. Takeaways
● Ports are just a name given to a common group of abstractions in your
domain
● Adapters are a group of specific implementations of a given port
● Onion Architecture, Clean Architecture and Ports & Adapters are
essentially the same thing
● Example repository on github for .NET
● Ports & Adapters is an architectural style that will produce applications
that are independent of infrastructure details