官术网_书友最值得收藏!

Hexagonal architecture

Hexagonal architecture (http://alistair.cockburn.us/Hexagonal+architecture), also known as the ports and adapters pattern, aims to decouple business logic from other parts of the component, especially the persistence and services layers. A component, built on the ports and adapters pattern, exposes a set of ports to which one or more adapters can be added as necessary. For example, to test and verify the core business logic in isolation, a mock database adapter can be plugged in and later replaced with a runtime database adapter in production.

A port is an entry point that is provided by the core business logic to interact with other parts of the component. An adapter is an implementation of a port, and there may be more than one adapter defined for a single port based on the requirement. For example, a REST adapter is used to accept requests from external users or other microservices components. It internally calls the service API port defined by the core business logic that performs that requested operation and generates a response. Similarly, a database adapter is used by the core business logic to interact with the external database via its database port, as shown in the following diagram:

Based on their applicability and usage, the REST adapter and database adapter are often referred to as primary and secondary adapters respectively. Similarly, the service API port and database port are referred to as primary and secondary ports respectively. Primary ports are called by the primary adapters and they act as the main interface between the core business logic and its users, whereas secondary ports and secondary adapters are used by the core business logic to generate events or interact with external services, like a database. Primary adapters help validate service requests with respect to a service schema and call core business logic functions, whereas the core business logic calls the functions of secondary adapters to help translate the application schema to the external service schema, like that of a database. Primary adapters are initialized with the application, but references to the secondary adapters are passed to the core business logic via dependency injection.

The name hexagonal architecture is derived from the structure of a component that has six ports, but that is not a rule. The idea of representing the architecture as a hexagon is just to remove the notion of one-dimensional layered architecture and have room to insert ports and adapters as required.
主站蜘蛛池模板: 溆浦县| 衡南县| 纳雍县| 东兰县| 建始县| 高淳县| 囊谦县| 瓮安县| 宜黄县| 台北市| 庆云县| 乌拉特中旗| 苍山县| 七台河市| 长春市| 灵山县| 久治县| 太仆寺旗| 屏南县| 田林县| 增城市| 德钦县| 平谷区| 五寨县| 宁武县| 鄂托克前旗| 泉州市| 香河县| 塔河县| 苍山县| 德化县| 鄂尔多斯市| 讷河市| 齐齐哈尔市| 南安市| 乌拉特前旗| 汉沽区| 青海省| 永靖县| 元江| 额敏县|