-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
375b7aa
commit d00aabd
Showing
11 changed files
with
499 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
# Ports | ||
# Ports in the Cronus Framework | ||
|
||
[https://github.com/Elders/Cronus/issues/258](https://github.com/Elders/Cronus/issues/258) | ||
In the Cronus framework, **Ports** facilitate communication between aggregates, enabling one aggregate to react to events triggered by another. This design promotes a decoupled architecture, allowing aggregates to interact through well-defined events without direct dependencies. | ||
|
||
Port is the mechanism to establish communication between aggregates. Usually, this involves one aggregate that triggered an event and one aggregate which needs to react. | ||
## Key Characteristics of Ports | ||
|
||
If you feel the need to do more complex interactions, it is advised to use Saga. The reason for this is that ports do not provide a transparent view of the business flow because they do not have a persistent state. | ||
- **Event-Driven Communication:** Ports listen for domain events—representing business changes that have already occurred—and dispatch corresponding commands to other aggregates that need to respond. | ||
|
||
## Communication Guide Table | ||
|
||
| Triggered by | Description | | ||
| ------------ | ------------------------------------------------------------------- | | ||
| Event | Domain events represent business changes that have already happened | | ||
- **Statelessness:** Ports do not maintain any persistent state. Their sole responsibility is to handle the routing of events to appropriate command handlers. | ||
|
||
## Best Practices | ||
## When to Use Ports | ||
|
||
{% hint style="success" %} | ||
**You can/should/must...** | ||
Ports are ideal for straightforward interactions where an event from one aggregate necessitates a direct response from another. However, for more complex workflows involving multiple steps or requiring state persistence, implementing a **Saga** is recommended. Sagas provide a transparent view of the business process and manage the state across various interactions, ensuring consistency and reliability. | ||
|
||
* a port can send a command | ||
{% endhint %} | ||
## Communication Guide Table | ||
|
||
| Triggered by | Description | | ||
|--------------|-------------------------------------------------------| | ||
| Event | Domain events represent business changes that have already happened. | | ||
|
||
By utilizing Ports appropriately, developers can design systems that are both modular and maintainable, adhering to the principles of Domain-Driven Design and Event Sourcing. | ||
|
||
**Port example** | ||
|
||
```csharp | ||
[DataContract(Name = "a44e9a38-ab13-4f86-844a-86fefa925b53")] | ||
public class AlertPort : IPort, | ||
IEventHandler<UserCreated> | ||
{ | ||
public Task HandleAsync(UserCreated @event) | ||
{ | ||
//Implement your custom logic here | ||
return Task.CompletedTask; | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.