-
Notifications
You must be signed in to change notification settings - Fork 6
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
Andrej Cimperšek
committed
Apr 13, 2021
1 parent
d29d363
commit 28a8cd3
Showing
2 changed files
with
80 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,66 @@ | ||
CQRS | ||
==== | ||
|
||
Example of a Command and CommandHandler | ||
--------------------------------------- | ||
|
||
```c# | ||
using CoreSharp.Cqrs.Command; | ||
|
||
public class TestCommand : ICommand | ||
{ | ||
public string Input { get; } | ||
|
||
public TestCommand(string input) | ||
{ | ||
Input = input ?? throw new ArgumentNullException(nameof(input)); | ||
} | ||
} | ||
|
||
public class TestCommandHandler : ICommandHandler<TestCommand> | ||
{ | ||
public void Handle(TestCommand command) | ||
{ | ||
Console.WriteLine(command.In()); | ||
} | ||
} | ||
``` | ||
|
||
Example of a Query and QueryHandler | ||
--------------------------------------- | ||
|
||
```c# | ||
using CoreSharp.Cqrs.Query; | ||
|
||
public class TestQuery : IQuery<string> | ||
{ | ||
public string Name { get; } | ||
|
||
public TestQuery(string name) | ||
{ | ||
Name = name ?? throw new ArgumentNullException(nameof(name)); | ||
} | ||
} | ||
|
||
public class TestQueryHandler : IQueryHandler<TestQuery, string> | ||
{ | ||
public string Handle(TestQuery query) | ||
{ | ||
return $"Hello {query.Name}"; | ||
} | ||
} | ||
``` | ||
|
||
Command and Query registration | ||
------------------------------ | ||
|
||
```c# | ||
// Register command & query handlers from Assembly of MyCommandOrQueryHandler | ||
container.RegisterCqrsFromAssemblyOf<MyCommandOrQueryHandler>(); | ||
|
||
// Register command handlers from Assembly of MyCommandHandler | ||
container.RegisterCommandHandlersFromAssemblyOf<MyCommandHandler>(); | ||
|
||
// Register query handlers from Assembly of MyQueryHandler | ||
container.RegisterQueryHandlersFromAssemblyOf<MyQueryHandler>(); | ||
``` |