-
-
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
44c6c8f
commit 7ec74ba
Showing
5 changed files
with
60 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Concepts | ||
|
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# CQRS | ||
|
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# DDD | ||
|
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,2 +1,53 @@ | ||
# Application Services | ||
|
||
This is a handler where commands are received and delivered to the addressed AggregateRoot. We call these handlers _ApplicationService_. This is the _write side_ in CQRS. | ||
|
||
## Communication Guide Table | ||
|
||
| Triggered by | Description | | ||
| :--- | :--- | | ||
| Command | A command is used to dispatch domain model changes. It can either be accepted or rejected depending on the domain model invariants | | ||
|
||
## Best Practices | ||
|
||
{% hint style="success" %} | ||
**You can/should/must...** | ||
|
||
* an appservice **can** load an aggregate root from the event store | ||
* an appservice **can** save new aggregate root events to the event store | ||
* an appservice **can** establish calls to the ReadModel \(not common practice but sometimes needed\) | ||
* an appservice **can** establish calls to external services | ||
* you **can** do dependency orchestration | ||
* an appservice **must** be stateless | ||
* an appservice **must** update only one aggregate root. Yes, this means that you can create one aggregate and update another one but think twice | ||
{% endhint %} | ||
|
||
{% hint style="warning" %} | ||
**You should not...** | ||
|
||
* an appservice **should not** update more than one aggregate root in single command/handler | ||
* you **should not** place domain logic inside an application service | ||
* you **should not** use application service to send emails, push notifications etc. Use Port or Gateway instead | ||
* an appservice **should not** update the ReadModel | ||
{% endhint %} | ||
|
||
## Examples | ||
|
||
```csharp | ||
public class AccountAppService : AggregateRootApplicationService<Account>, | ||
ICommandHandler<RegisterAccount>, | ||
ICommandHandler<ActivateAccount>, | ||
ICommandHandler<SuspendAccount>, | ||
ICommandHandler<ResetAccountPassword>, | ||
ICommandHandler<ChangeAccountEmail>, | ||
ICommandHandler<ChangeAccountUsername> | ||
{ | ||
public void Handle(SuspendAccount message) | ||
{ | ||
Update(message.Id, account => account.Suspend()); | ||
} | ||
|
||
... | ||
} | ||
``` | ||
|