This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Showing
37 changed files
with
743 additions
and
82 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
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,120 @@ | ||
# Command Sequence | ||
|
||
With Kledex is possible to create a squence of commands that will be executed in the specified order. | ||
|
||
First, create the commands that need to be part of the sequence: | ||
|
||
```C# | ||
public class FirstCommand : Command | ||
{ | ||
} | ||
|
||
public class SecondCommand : Command | ||
{ | ||
} | ||
|
||
public class ThirdCommand : Command | ||
{ | ||
} | ||
``` | ||
|
||
Next, as you would have done normally create the handlers for your commands. | ||
The only difference is that the handlers need to implement the **ISequenceCommandHandlerAsync<>** interface. | ||
The _HandlerAsync_ of this interface accepts an extra parameter which is a _CommandResponse_. | ||
Kledex will pass automatically the command response of the previous command in the sequence. | ||
For the first hanlder it would obviously be null. | ||
|
||
First command handler: | ||
|
||
```C# | ||
public class FirstCommandHandler : ISequenceCommandHandlerAsync<FirstCommand> | ||
{ | ||
public Task<CommandResponse> HandleAsync(FirstCommand command, CommandResponse previousStepResponse) | ||
{ | ||
Console.WriteLine("Message from first command handler"); | ||
|
||
return Task.FromResult(new CommandResponse | ||
{ | ||
Result = "First result" | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
Second command handler: | ||
|
||
```C# | ||
public class SecondCommandHandler : ISequenceCommandHandlerAsync<SecondCommand> | ||
{ | ||
public Task<CommandResponse> HandleAsync(SecondCommand command, CommandResponse previousStepResponse) | ||
{ | ||
Console.WriteLine($"Message from second command handler. Result from first handler: {previousStepResponse.Result}"); | ||
|
||
return Task.FromResult(new CommandResponse | ||
{ | ||
Result = "Second result" | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
Third command handler: | ||
|
||
```C# | ||
public class ThirdCommandHandler : ISequenceCommandHandlerAsync<ThirdCommand> | ||
{ | ||
public Task<CommandResponse> HandleAsync(ThirdCommand command, CommandResponse previousStepResponse) | ||
{ | ||
Console.WriteLine($"Message from third command handler. Result from second handler: {previousStepResponse.Result}"); | ||
|
||
return Task.FromResult(new CommandResponse | ||
{ | ||
Result = "Third result" | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
Last, create a class that inherits from the _CommandSequence_ abstract class and add all your commands: | ||
|
||
```C# | ||
public class SampleCommandSequence : CommandSequence | ||
{ | ||
public SampleCommandSequence() | ||
{ | ||
AddCommand(new FirstCommand()); | ||
AddCommand(new SecondCommand()); | ||
AddCommand(new ThirdCommand()); | ||
} | ||
} | ||
``` | ||
|
||
Use the dispatcher to execute the command sequence: | ||
|
||
```C# | ||
await dispatcher.SendAsync(new SampleCommandSequence()); | ||
``` | ||
|
||
You can also get a result from the sequence which will be the value of the Result property of the command response of the last command in the sequence (in our example of the ThirdCommand): | ||
|
||
```C# | ||
var result = await dispatcher.SendAsync<string>(new SampleCommandSequence()); | ||
``` | ||
|
||
The following is the output generated: | ||
|
||
``` | ||
Message from first command handler | ||
Message from second command handler. Result from first handler: First result | ||
Message from third command handler. Result from second handler: Second result | ||
Final result: Third result | ||
``` | ||
|
||
You can find the sample code [here](https://github.com/lucabriguglia/Kledex/tree/master/samples/Kledex.Sample.CommandSequence) | ||
|
||
## Related | ||
|
||
- [Commands](Commands) | ||
- [Command Validation](Command-Validation) | ||
- [Domain Commands With Event Sourcing](With-Event-Sourcing) | ||
- [Domain Commands Without Event Sourcing](Without-Event-Sourcing) |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Domain Commands | ||
|
||
Working with your domain model: | ||
|
||
- [Domain Commands With Event Sourcing](With-Event-Sourcing) | ||
- [Domain Commands Without Event Sourcing](Without-Event-Sourcing) |
This file was deleted.
Oops, something went wrong.
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,3 +1,15 @@ | ||
# UI | ||
|
||
Work in progress... | ||
The UI package is an experimental package that can be used to display information about an aggregate and its events: | ||
|
||
```C# | ||
var model = await _dispatcher.GetResultAsync(new GetAggregateModel | ||
{ | ||
AggregateRootId = id | ||
}); | ||
``` | ||
|
||
The model will contain the list of all events of the aggregate ordered by time stamp descending. | ||
Further improvements will be made in coming versions. | ||
|
||
You can find a sample usage [here](https://github.com/lucabriguglia/Kledex/blob/master/samples/Kledex.Sample.EventSourcing/Pages/Edit.cshtml.cs). |
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.