You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-3Lines changed: 15 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,20 @@
1
1
# dotnet-dispatcher 0.1
2
+
2
3
A simple dispatcher for .NET Core that uses Roslyn code generation to emit CQRS dispatcher code. Currently in extremely early stage, but I feel there's something to it.
3
4
4
5
## Why?
6
+
5
7
I'm a great 'not-friend' of things like reflection, Activator and runtime type determination. When writing CQRS code, I would like to have my dispatcher code generated in compile time, with all optimalizations and other goodies that come with it.
Aside from the Dispatch code, a matching interface is also generated. This allows for easy mocking of the dispatcher as well as using dependency injection. You can have multiple dispatchers in a project, if you want to. Alternatively, you can repeat the use of the GenerateDispatcher attribute with other types that implement `IQuery<TResponse>`, `ICommand<TResponse>` or `ICommand`.
46
48
49
+
Aside from the Dispatch code, a matching interface is also generated. This allows for easy mocking of the dispatcher as well as using dependency injection. You can have multiple dispatchers in a project, if you want to. Alternatively, you can repeat the use of the GenerateDispatcher attribute with other types that implement `IQuery<TResponse>`, `ICommand<TResponse>` or `ICommand`.
47
50
48
51
## Download and install
52
+
49
53
There are three nuget packages to install:
54
+
50
55
-`DotnetDispatcher.Core` - contains interfaces your commands and queries should implement, as well as the `DispatcherBase` class
51
56
-`DotnetDispatcher.Attributes` - contains the `GenerateDispatcher` attribute
52
57
-`DotnetDispatcher.Generator` - contains the code generator
53
58
54
59
## How to use
60
+
55
61
Assuming you have an API project and a Domain project in your solution, where the generated dispatcher is part of the API project and the commands and queries are part of the Domain project:
62
+
56
63
- The API project should reference the Domain project, as well as the `DotnetDispatcher.Generator` and `DotnetDispatcher.Attributes` packages
57
64
- The Domain project should reference the `DotnetDispatcher.Core` package
58
65
59
66
The actual implementation in the projects is as such:
67
+
60
68
- The domain project contains the query and the query handler
@@ -82,7 +92,9 @@ public partial class MyAppDispatcher : DispatcherBase
82
92
}
83
93
}
84
94
```
95
+
85
96
This generates the dispatcher code as well as an IServiceCollection extension method that allows you to register the dispatcher in the DI container. You can use it in the API project like this:
0 commit comments