Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Version #1

Merged
merged 178 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
b3d9b65
Add Attributes and `Behavior` base class
viceroypenguin Jan 5, 2024
44cc494
Add Initial Generator code
viceroypenguin Jan 5, 2024
7f99ef6
Fix debugging
viceroypenguin Jan 5, 2024
fe1c487
Update `RenderMode` FAWMN
viceroypenguin Jan 5, 2024
bc31fd7
Implement `TransformRenderMode`
viceroypenguin Jan 5, 2024
dcdbc20
Behaviors list should be overridable
viceroypenguin Jan 5, 2024
ef565ef
Change attributes project to `.Shared`
viceroypenguin Jan 5, 2024
1ea0562
Implement first draft of `TransformBehavior`
viceroypenguin Jan 5, 2024
bc318d2
rename `RenderModeAttribute.cs` file
viceroypenguin Jan 5, 2024
cfad2b2
misc in-progress work
viceroypenguin Jan 5, 2024
f7b7f1c
More effects from project name change
viceroypenguin Jan 5, 2024
a4e66b7
cleanup
viceroypenguin Jan 5, 2024
a319a89
Handler Renderer needs info on msdi as well
viceroypenguin Jan 5, 2024
5112d67
Add *.received.* files to source control for snapshot testing setup
Jan 6, 2024
86778a2
Initial unit testing setup using snapshots
Jan 6, 2024
7198788
fix nuget packages
viceroypenguin Jan 6, 2024
73ccfc1
ignore rider temp files
viceroypenguin Jan 6, 2024
72474ae
add reference assemblies to unit tests.
viceroypenguin Jan 6, 2024
dc278d6
Fix indentation for normal source fragment
Jan 6, 2024
1d27c19
Add option for retrieving a compilation object with MSDI as a referen…
Jan 6, 2024
f9020ce
.editorconfig settings?
viceroypenguin Jan 6, 2024
7bd04f1
Implement `TransformHandler`
viceroypenguin Jan 6, 2024
119a8da
- Added initial handler generation draft
Sossenbinder Jan 6, 2024
6c0cbe6
compiles again
viceroypenguin Jan 6, 2024
3577e57
- Added compile clean, but still somewhat hardcoded Handlers template
Sossenbinder Jan 6, 2024
1665049
revert simplistic check
viceroypenguin Jan 6, 2024
9e55dcb
Improve contract
viceroypenguin Jan 6, 2024
adb1a0b
- Added FQDN to handler name
Sossenbinder Jan 6, 2024
70ba482
- Corrected FQDN parameter type name resolution
Sossenbinder Jan 6, 2024
0787713
- Moved return type away from the hardcoded value
Sossenbinder Jan 6, 2024
d886ff4
Add `OverrideRenderMode`
viceroypenguin Jan 6, 2024
c773b1c
Improve cancellation
viceroypenguin Jan 6, 2024
1aea8c0
- Added parameter translation
Sossenbinder Jan 6, 2024
cabecd5
Fix Incorrect TransformBehaviors cacheability
viceroypenguin Jan 6, 2024
7821784
Add `OverrideBehaviors`
viceroypenguin Jan 6, 2024
3163975
Ensure override behaviors get registered
viceroypenguin Jan 6, 2024
981c83f
Remove unnecessary interface
viceroypenguin Jan 6, 2024
ec190a8
- Added behaviours to Handlers.sbntxt
Sossenbinder Jan 6, 2024
294acc8
Move code around
Jan 6, 2024
8aa77d9
Move types back into ImmediateHandlersGenerator class as private chil…
Jan 6, 2024
c66dd14
simplify test code
viceroypenguin Jan 6, 2024
9ff406a
fix debugging
viceroypenguin Jan 6, 2024
da11365
Test generates code now
viceroypenguin Jan 6, 2024
5e4b0a6
- Fixed service collection generation by actually passing the display…
Sossenbinder Jan 6, 2024
d3676e5
Fix service collection rendering
Jan 6, 2024
d2bf95f
use os line endings
viceroypenguin Jan 6, 2024
092fd02
Revert "Fix service collection rendering"
viceroypenguin Jan 6, 2024
2cfcef6
Add tests for multi and single behavior scenarios
Jan 6, 2024
3c25238
Add public api xmldoc
viceroypenguin Jan 6, 2024
a874898
Fix typos
viceroypenguin Jan 6, 2024
27da363
Correct spelling, only to match existing uses of the word `Behavior`
viceroypenguin Jan 6, 2024
17368d4
Fix tests
viceroypenguin Jan 6, 2024
6ce2506
Modify unit tests to use theories and parameterize the generated snap…
Jan 7, 2024
56ace7b
- Added initial functional tests to actually verify the generated code
Sossenbinder Jan 7, 2024
8501a48
correct sln file
viceroypenguin Jan 7, 2024
0e10687
Simplify Assembly selection in tests
viceroypenguin Jan 7, 2024
a39cecc
correct output filename
viceroypenguin Jan 7, 2024
5a17e78
mark type static
viceroypenguin Jan 7, 2024
cf290aa
Support overrides and prepare for pipeline parsing
viceroypenguin Jan 7, 2024
01e1ccc
Improve Behaviors API shape
viceroypenguin Jan 7, 2024
ca974ab
add more cancellation opportunities
viceroypenguin Jan 7, 2024
3fac05d
Finish transforming behaviors
viceroypenguin Jan 7, 2024
3c6463f
Fix list type for scriban
viceroypenguin Jan 7, 2024
f0faa90
Implement behavior filtering
viceroypenguin Jan 7, 2024
f3cba71
cleanup
viceroypenguin Jan 7, 2024
decf327
Disable CS1591 (xmldoc) in generated files
viceroypenguin Jan 7, 2024
1516721
- Added parameterized handler test
Sossenbinder Jan 7, 2024
6330d75
- Disabled warnings for sample project & tests
Sossenbinder Jan 7, 2024
85f46cd
- Added gh actions testlogger for new test project
Sossenbinder Jan 7, 2024
6e11e5c
correct warning process
viceroypenguin Jan 7, 2024
b8ecfec
Add analyzer testing framework & analyzer and codefix projects
Jan 7, 2024
078184a
Fix test for handler method does not exist
Jan 7, 2024
ac31b77
- Added .ConfigureAwait(false) to generated awaits
Sossenbinder Jan 7, 2024
25113cb
Add analyzers for task<t> return and handler having atleast a request…
Jan 7, 2024
1308b4a
Remove DriverReferenceAssemblies from analyzer test helpers
Jan 7, 2024
9b9f795
Rename diagnostic
Jan 7, 2024
d8a8f8c
Fix all warnings
Jan 7, 2024
72eb47a
reverting invalid .editorconfig change
viceroypenguin Jan 7, 2024
cf61549
chore: cleanup of warnings and editorconfig/csproj
sid-6581 Jan 8, 2024
91e7c46
chore: fix warning
sid-6581 Jan 8, 2024
7006127
Fix `AnalyzerReleases` files
viceroypenguin Jan 8, 2024
c6eace0
Remove localization for now
viceroypenguin Jan 8, 2024
cf8dacd
Clean up csproj files
viceroypenguin Jan 8, 2024
e6c6dbb
Remove unnecessary readme.md files
viceroypenguin Jan 8, 2024
8b5cd97
Fix build
viceroypenguin Jan 8, 2024
ecb86a4
refactor generators to `Immediate.Handlers.Generators`
viceroypenguin Jan 8, 2024
7828ef7
Simplify analyzer code
viceroypenguin Jan 8, 2024
1b28057
fix build error
viceroypenguin Jan 8, 2024
eba0ecf
address tests
viceroypenguin Jan 8, 2024
0a74818
Improve rendered code layout
viceroypenguin Jan 8, 2024
6ba244a
fix rider complaint
viceroypenguin Jan 8, 2024
5a5bd8e
cleanup .csproj files
viceroypenguin Jan 8, 2024
10c20ff
Build nuget package
viceroypenguin Jan 8, 2024
bc78565
correct roslyn version in nuget package
viceroypenguin Jan 8, 2024
21a8cd3
chore: fix editorconfig and line endings
sid-6581 Jan 8, 2024
ba71244
chore: fix some Rider inspections
sid-6581 Jan 8, 2024
0f82a53
chore: remove remaining BOM
sid-6581 Jan 8, 2024
0e05005
Simplify tests
viceroypenguin Jan 8, 2024
80aef23
`RenderModeAttribute` should only use constructor arguments
viceroypenguin Jan 8, 2024
746d8f2
Remove code coverage analysis for support class
viceroypenguin Jan 8, 2024
3da49ce
Fix build issue
viceroypenguin Jan 8, 2024
40f8e9a
Address unit test changes
viceroypenguin Jan 8, 2024
5e2b520
reorganize tests
viceroypenguin Jan 8, 2024
a001f90
More reorganization
viceroypenguin Jan 8, 2024
56ffa24
more test reorganization
viceroypenguin Jan 8, 2024
550eb28
Add more test coverage of analyzer
viceroypenguin Jan 8, 2024
0a606f7
Add base classes for handler code fixes
Jan 8, 2024
6f787c3
move codefix tests
Jan 8, 2024
bc34229
Add support for Task aswell as Task<T> as a handleasync method return…
Jan 8, 2024
7ed3ee3
Changed my mind - won't support `Task` after all
viceroypenguin Jan 8, 2024
fc7a9d6
Fix codefix test
Jan 8, 2024
914bf32
Add .editorconfig to test
viceroypenguin Jan 8, 2024
bfddaef
Add debug launch targets
viceroypenguin Jan 8, 2024
2746403
Fix code-fix
viceroypenguin Jan 8, 2024
5120d7d
add a default fix-all provider
viceroypenguin Jan 8, 2024
0cd1c4b
Mark class `sealed`
viceroypenguin Jan 8, 2024
c473e5e
Add invalid render mode attribute
viceroypenguin Jan 8, 2024
b984c00
Update diagnostic IDs
viceroypenguin Jan 8, 2024
271f2d2
Fix remaining ihr ids
viceroypenguin Jan 8, 2024
83512b2
RenderMode analyzer should be a warning
viceroypenguin Jan 8, 2024
6c38c3b
Add documentation for `IHR0004`
viceroypenguin Jan 8, 2024
7d6a3cd
Missed file in warning change
viceroypenguin Jan 8, 2024
c9d26ed
Add tests for `RenderModeAnalyzer`
viceroypenguin Jan 8, 2024
07e1f50
Shorten hint names
viceroypenguin Jan 8, 2024
3f18658
Restore IHR0004 to an error
viceroypenguin Jan 8, 2024
2945281
`InvalidRenderModeTest`
viceroypenguin Jan 8, 2024
ffea1fe
Address unit test failures
viceroypenguin Jan 8, 2024
173702a
`InvalidBehaviorsTests`
viceroypenguin Jan 8, 2024
150303b
Remove recursive constraint check
viceroypenguin Jan 8, 2024
3f389cf
record types do not need to be unit tested
viceroypenguin Jan 8, 2024
2724173
Fix invalid tests
viceroypenguin Jan 8, 2024
f476913
Add coverage for msdi with invalid behavior
viceroypenguin Jan 8, 2024
fb74635
- Added new Analyzer to check whether the handler is nested in anothe…
Sossenbinder Jan 8, 2024
6249e60
Framework for BehaviorsAnalyzer
viceroypenguin Jan 8, 2024
aad5b43
move token check to better spot
viceroypenguin Jan 8, 2024
0f9f8b3
`InvalidHandlerTests`
viceroypenguin Jan 8, 2024
ea7d187
restore minver to package versioning
viceroypenguin Jan 8, 2024
6bc1482
Fix packaging csproj
viceroypenguin Jan 8, 2024
9d7725c
Make fewer assumptions about the handler class
viceroypenguin Jan 8, 2024
3cb9af5
update .verified files for template change
viceroypenguin Jan 8, 2024
2efa697
clean up template whitespace
viceroypenguin Jan 8, 2024
6109bbe
Fix `default(EquatableReadOnlyList<T>)`
viceroypenguin Jan 9, 2024
379944f
chore: fix project name
sid-6581 Jan 9, 2024
4872df0
Add Analyzers and UnitTests for Behaviors
Head0nF1re Jan 9, 2024
0c4a9b3
Add missing tests for Behaviors declared in class
Head0nF1re Jan 9, 2024
0bccc42
Remove comments in DiagnosticIds
Head0nF1re Jan 9, 2024
3892525
Improve API of `Shared.Behavior`
viceroypenguin Jan 9, 2024
e1c9877
Fix bug in ordering of behaviors
viceroypenguin Jan 9, 2024
9f5e096
Update template to handle `Handle()` as well as `HandleAsync()`
viceroypenguin Jan 9, 2024
3b77d79
Add analyzer to check if a command or query is defined in a handler c…
Jan 9, 2024
442429d
Correctly handle no namespace
viceroypenguin Jan 9, 2024
17624a6
Simplify analyzer test
viceroypenguin Jan 9, 2024
07b2406
fix namespace
viceroypenguin Jan 9, 2024
331c12a
Simplify more unit tests
Jan 9, 2024
9361e98
share diagnostic ids
viceroypenguin Jan 9, 2024
996f518
Simplify codefix test
Jan 9, 2024
615b3d4
simplify layout
viceroypenguin Jan 9, 2024
c4a8138
use expression bodies
viceroypenguin Jan 9, 2024
3088c08
Update BehaviorAnalyzerTests to new pattern
Head0nF1re Jan 9, 2024
431b5bb
Update Behavior tests
viceroypenguin Jan 9, 2024
397f98c
Separate `Handler` and `Behavior` registration
viceroypenguin Jan 9, 2024
11ab954
Add codefixes for command and query records
Jan 9, 2024
0ddf4e4
Add preliminary readme.md
viceroypenguin Jan 9, 2024
5802ca4
Add IHR6-8 docs
viceroypenguin Jan 9, 2024
9026101
Add more docs, misc analyzer fixes
Jan 9, 2024
1eb7d80
Fix diagnostic severity & build error
Jan 9, 2024
eac0715
fix typo
Jan 9, 2024
a9aab83
Address Rider complaints
viceroypenguin Jan 10, 2024
85f0727
style: fix crazy line length and standardize some style
sid-6581 Jan 10, 2024
652d787
improve further
viceroypenguin Jan 10, 2024
f8deefd
Simplify check
viceroypenguin Jan 10, 2024
318bb51
more code style improvements
viceroypenguin Jan 10, 2024
02d65d1
feat: add initial API sample
sid-6581 Jan 10, 2024
387afaa
wrap longer lines in template
viceroypenguin Jan 10, 2024
6b9383a
Add link to sample
viceroypenguin Jan 10, 2024
145c9c7
remove redundant line
viceroypenguin Jan 10, 2024
ce178ff
fix: fix analyzer strings
sid-6581 Jan 10, 2024
6da12c6
Improve behavior analyzer text
viceroypenguin Jan 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,34 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = tab
insert_final_newline = true

# Build scripts
[*.{yml,yaml}]
indent_style = spaces
indent_size = 2

# XML project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj,props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_style = tab
indent_size = 2

# Verify settings

[*.{received,verified}.{txt,xml,json,cs}]
indent_size = unset
indent_style = unset
insert_final_newline = false
tab_width = unset
trim_trailing_whitespace = false

# Code files
[*.cs]
indent_size = 4
tab_width = 4
charset = utf-8-bom
max_line_length = 150

## Dotnet code style settings:

Expand All @@ -31,10 +42,10 @@ dotnet_separate_import_directive_groups = false
dotnet_style_require_accessibility_modifiers = for_non_interface_members:error

# Avoid "this." and "Me." if not necessary
dotnet_style_qualification_for_field = false:refactoring
dotnet_style_qualification_for_property = false:refactoring
dotnet_style_qualification_for_method = false:refactoring
dotnet_style_qualification_for_event = false:refactoring
dotnet_style_qualification_for_field = false
dotnet_style_qualification_for_property = false
dotnet_style_qualification_for_method = false
dotnet_style_qualification_for_event = false

# Use language keywords instead of framework type names for type references
dotnet_style_predefined_type_for_locals_parameters_members = true:error
Expand Down Expand Up @@ -182,7 +193,7 @@ csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = do_not_ignore
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
Expand All @@ -200,8 +211,16 @@ csharp_space_between_square_brackets = false

# Blocks are allowed
csharp_prefer_braces = when_multiline:silent
csharp_preserve_single_line_blocks = true:silent
csharp_preserve_single_line_statements = true:silent
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true

# Resharper/Rider inspections
resharper_trailing_comma_in_multiline_lists = true
resharper_align_multiline_binary_expressions_chain = false
resharper_align_multiline_comments = false
resharper_align_multiline_statement_conditions = false
resharper_indent_raw_literal_string = do_not_change
resharper_csharp_max_line_length = 150

# Style Analytics
dotnet_analyzer_diagnostic.category-Style.severity = warning
Expand All @@ -215,6 +234,13 @@ dotnet_diagnostic.CS1712.severity = none # CS1712: Type parameter
# Async
dotnet_diagnostic.CS1998.severity = error # CS1998: Async method lacks 'await' operators and will run synchronously
dotnet_diagnostic.CS4014.severity = error # CS4014: Because this call is not awaited, execution of the current method continues before the call is completed
dotnet_diagnostic.CA2007.severity = none # CA2007: Consider calling ConfigureAwait on the awaited task

# Immediate.Handlers relies on nested types
dotnet_diagnostic.CA1034.severity = none # CA1034: Nested types should not be visible

# No need for cryptographically secure anything in this project
dotnet_diagnostic.CA5394.severity = none # CA5394: Random is an insecure random number generator

# Dispose things need disposing
dotnet_diagnostic.CA2000.severity = error # CA2000: Dispose objects before losing scope
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* text=auto eol=lf
* text=auto
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@
# VS Code cache/options directory
.vscode/

# Rider temporary files
.idea/

# TestResults
[Tt]est[Rr]esults/

# Verify
*.received.*
7 changes: 4 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<TargetFramework>net8.0</TargetFramework>

<Nullable>enable</Nullable>
<WarningsAsErrors>$(WarningsAsErrors);nullable;</WarningsAsErrors>
Expand All @@ -11,16 +12,16 @@
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>

<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PolySharp" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<!-- Don't block development work; but block CI if dev work isn't complete. -->
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<CollectCoverage>true</CollectCoverage>
Expand Down
47 changes: 30 additions & 17 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.0" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.3.3" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="MinVer" Version="4.3.0" />
<PackageVersion Include="PolySharp" Version="1.14.1" />
<PackageVersion Include="Scriban" Version="5.9.0" />
<PackageVersion Include="xunit" Version="2.6.4" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Basic.Reference.Assemblies" Version="1.4.5" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.0" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.3.3" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1" />
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="1.1.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.1.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.8.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="MinVer" Version="4.3.0" />
<PackageVersion Include="PolySharp" Version="1.14.1" />
<PackageVersion Include="Scriban" Version="5.9.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="Verify.SourceGenerators" Version="2.2.0" />
<PackageVersion Include="Verify.Xunit" Version="22.11.4" />
<PackageVersion Include="xunit" Version="2.6.5" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
</ItemGroup>
</Project>
32 changes: 30 additions & 2 deletions Immediate.Handlers.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
Expand Down Expand Up @@ -27,12 +27,20 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{C484
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immediate.Handlers", "src\Immediate.Handlers\Immediate.Handlers.csproj", "{4E9DC4CB-4833-4471-AF34-699565BCFDBE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immediate.Handlers.Utility", "src\Immediate.Handlers.Utility\Immediate.Handlers.Utility.csproj", "{789B0C8D-98ED-4712-8AB1-E4B10AD4D669}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immediate.Handlers.Shared", "src\Immediate.Handlers.Shared\Immediate.Handlers.Shared.csproj", "{789B0C8D-98ED-4712-8AB1-E4B10AD4D669}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immediate.Handlers.Tests", "tests\Immediate.Handlers.Tests\Immediate.Handlers.Tests.csproj", "{7E5E76EB-8087-48F6-8A87-CFABFC5CB409}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Normal", "samples\Normal\Normal.csproj", "{4E8FA4AC-7802-4775-AF8B-781B199EE5E6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immediate.Handlers.FunctionalTests", "tests\Immediate.Handlers.FunctionalTests\Immediate.Handlers.FunctionalTests.csproj", "{DB656BD6-AFA3-4285-8CD6-4EA91DB36D65}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immediate.Handlers.CodeFixes", "src\Immediate.Handlers.CodeFixes\Immediate.Handlers.CodeFixes.csproj", "{0A786D44-F49E-46F6-A97E-9E8B75A12829}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immediate.Handlers.Analyzers", "src\Immediate.Handlers.Analyzers\Immediate.Handlers.Analyzers.csproj", "{E9AF88B6-8719-4FDD-B99E-F060BB116073}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immediate.Handlers.Generators", "src\Immediate.Handlers.Generators\Immediate.Handlers.Generators.csproj", "{848CB147-CB80-448E-A1B1-30231A4F843C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -55,6 +63,22 @@ Global
{4E8FA4AC-7802-4775-AF8B-781B199EE5E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E8FA4AC-7802-4775-AF8B-781B199EE5E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E8FA4AC-7802-4775-AF8B-781B199EE5E6}.Release|Any CPU.Build.0 = Release|Any CPU
{DB656BD6-AFA3-4285-8CD6-4EA91DB36D65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DB656BD6-AFA3-4285-8CD6-4EA91DB36D65}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB656BD6-AFA3-4285-8CD6-4EA91DB36D65}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB656BD6-AFA3-4285-8CD6-4EA91DB36D65}.Release|Any CPU.Build.0 = Release|Any CPU
{0A786D44-F49E-46F6-A97E-9E8B75A12829}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A786D44-F49E-46F6-A97E-9E8B75A12829}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A786D44-F49E-46F6-A97E-9E8B75A12829}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A786D44-F49E-46F6-A97E-9E8B75A12829}.Release|Any CPU.Build.0 = Release|Any CPU
{E9AF88B6-8719-4FDD-B99E-F060BB116073}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E9AF88B6-8719-4FDD-B99E-F060BB116073}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9AF88B6-8719-4FDD-B99E-F060BB116073}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9AF88B6-8719-4FDD-B99E-F060BB116073}.Release|Any CPU.Build.0 = Release|Any CPU
{848CB147-CB80-448E-A1B1-30231A4F843C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{848CB147-CB80-448E-A1B1-30231A4F843C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{848CB147-CB80-448E-A1B1-30231A4F843C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{848CB147-CB80-448E-A1B1-30231A4F843C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -65,6 +89,10 @@ Global
{789B0C8D-98ED-4712-8AB1-E4B10AD4D669} = {48400D35-471A-4EF4-93E4-2394D87E0012}
{7E5E76EB-8087-48F6-8A87-CFABFC5CB409} = {517768B6-A2B3-4ED2-8F70-E53C85A493FF}
{4E8FA4AC-7802-4775-AF8B-781B199EE5E6} = {C484CFC6-6DB0-48CB-A769-1A06FF40787E}
{DB656BD6-AFA3-4285-8CD6-4EA91DB36D65} = {517768B6-A2B3-4ED2-8F70-E53C85A493FF}
{0A786D44-F49E-46F6-A97E-9E8B75A12829} = {48400D35-471A-4EF4-93E4-2394D87E0012}
{E9AF88B6-8719-4FDD-B99E-F060BB116073} = {48400D35-471A-4EF4-93E4-2394D87E0012}
{848CB147-CB80-448E-A1B1-30231A4F843C} = {48400D35-471A-4EF4-93E4-2394D87E0012}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {184E3CAB-91E8-4F1A-A16B-C062F25BECC4}
Expand Down
3 changes: 3 additions & 0 deletions Immediate.Handlers.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeObjectCreationWhenTypeNotEvident/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Msdi/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
133 changes: 130 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,139 @@
# Immediate.Handlers
| Name | Status | History |
| :--- | :--- | :--- |
| GitHub Actions | ![Build](https://github.com/viceroypenguin/Immediate.Handlers/actions/workflows/build.yml/badge.svg) | [![GitHub Actions Build History](https://buildstats.info/github/chart/viceroypenguin/Immediate.Handlers?branch=master&includeBuildsFromPullRequest=false)](https://github.com/viceroypenguin/Immediate.Handlers/actions) |

[![NuGet](https://img.shields.io/nuget/v/Immediate.Handlers.svg?style=plastic)](https://www.nuget.org/packages/Immediate.Handlers/)
[![GitHub release](https://img.shields.io/github/release/viceroypenguin/Immediate.Handlers.svg)](https://GitHub.com/viceroypenguin/Immediate.Handlers/releases/)
[![GitHub license](https://img.shields.io/github/license/viceroypenguin/Immediate.Handlers.svg)](https://github.com/viceroypenguin/Immediate.Handlers/blob/master/license.txt)
[![GitHub issues](https://img.shields.io/github/issues/viceroypenguin/Immediate.Handlers.svg)](https://GitHub.com/viceroypenguin/Immediate.Handlers/issues/)
[![GitHub issues-closed](https://img.shields.io/github/issues-closed/viceroypenguin/Immediate.Handlers.svg)](https://GitHub.com/viceroypenguin/Immediate.Handlers/issues?q=is%3Aissue+is%3Aclosed)
[![GitHub Actions](https://github.com/viceroypenguin/Immediate.Handlers/actions/workflows/build.yml/badge.svg)](https://github.com/viceroypenguin/Immediate.Handlers/actions)
---

Immediate.Handlers is an implementation of the mediator pattern in .NET using source-generation. All pipeline behaviors
are determined and the call-tree built at compile-time; meaning that all dependencies are enforced via compile-time
safety checks. Behaviors and dependencies are obtained via DI at runtime based on compile-time determined dependencies.

#### Examples
* Minimal Api: [Normal](./samples/Normal)

## Installing Immediate.Handlers

You can install [Immediate.Handlers with NuGet](https://www.nuget.org/packages/Immediate.Handlers):

Install-Package Immediate.Handlers

Or via the .NET Core command line interface:

dotnet add package Immediate.Handlers

Either commands, from Package Manager Console or .NET Core CLI, will download and install Immediate.Handlers.

## Using Immediate.Handlers
### Creating Handlers

Create a Handler by adding the following code:

```cs
[Handler]
public static class GetUsersQuery
{
public record Query;

private static Task<IEnumerable<User>> HandleAsync(
Query _,
UsersService usersService,
CancellationToken token)
{
return usersService.GetUsers();
}
}
```

This will automatically create a new class, `GetUsersQuery.Handler`, which encapsulates the following:
* attaching any behaviors defined for all queries in the assembly
* using a class to receive any DI services, such as `UsersService`

Any consumer can now do the following:
```cs
public class Consumer(GetUsersQuery.Handler handler)
{
public async Task Consumer(CancellationToken token)
{
var response = await handler.HandleAsync(new(), token);
// do something with response
}
}
```

### Creating Behaviors

Create a behavior by implementing the `Immediate.Handlers.Shared.Behaviors<,>` class, as so:
```cs
public sealed class LoggingBehavior<TRequest, TResponse>(ILogger<LoggingBehavior<TRequest, TResponse>> logger)
: Behavior<TRequest, TResponse>
{
public override async Task<TResponse> HandleAsync(TRequest request, CancellationToken cancellationToken)
{
logger.LogInformation("LoggingBehavior.Enter");
var response = await Next(request, cancellationToken);
logger.LogInformation("LoggingBehavior.Exit");
return response;
}
}
```

This can be registered assembly-wide using:
```cs
[assembly: Behaviors(
typeof(LoggingBehavior<,>)
)]
```

or on an individual handler using:
```cs
[Handler]
[Behavior(
typeof(LoggingBehavior<,>)
)]
public static class GetUsersQuery
{
// ..
}
```

Once added to the pipeline, the behavior will be called as part of the pipeline to handle a request.

Note: adding a `[Behavior]` attribute to a handler will disregard all assembly-wide behaviors for that handler, so any
global behaviors necessary must be independently added to the handler override behaviors list.

#### Behavior Constraints

A constraint can be added to a behavior by using:
```cs
public sealed class LoggingBehavior<TRequest, TResponse>
: Behavior<TRequest, TResponse>
where TRequest : IRequestConstraint
where TResponse : IResponseConstraint
```

When a pipeline is generated, all potential behaviors are evaluated against the request and response types, and if
either type does not match a given constraint, the behavior is not added to the generated pipeline.

### Registering with `IServiceCollection`

Immediate.Handlers supports `Microsoft.Extensions.DependencyInjection.Abstractions` directly.

#### Registering Handlers

```cs
services.AddHandlers();
```

This registers all classes in the assembly marked with `[Handler]`.

#### Registering Behaviors

```cs
services.AddBehaviors();
```

This registers all behaviors referenced in any `[Behaviors]` attribute.
Loading