Showing preview only (485K chars total). Download the full file or copy to clipboard to get everything.
Repository: LuckyPennySoftware/MediatR
Branch: main
Commit: f72aef8d786f
Files: 182
Total size: 438.7 KB
Directory structure:
gitextract_64igt8ai/
├── .editorconfig
├── .gitattributes
├── .github/
│ └── workflows/
│ ├── ci.yml
│ ├── release.yml
│ └── triage-issues.yml
├── .gitignore
├── Build.ps1
├── BuildContracts.ps1
├── Directory.Build.props
├── LICENSE.md
├── MediatR.slnx
├── MediatR.snk
├── NuGet.Config
├── Push.ps1
├── README.md
├── samples/
│ ├── MediatR.Examples/
│ │ ├── ConstrainedRequestPostProcessor.cs
│ │ ├── ExceptionHandler/
│ │ │ ├── Exceptions.cs
│ │ │ ├── ExceptionsHandlers.cs
│ │ │ ├── ExceptionsHandlersOverrides.cs
│ │ │ ├── Handlers.cs
│ │ │ ├── LogExceptionAction.cs
│ │ │ ├── Requests.cs
│ │ │ └── RequestsOverrides.cs
│ │ ├── GenericHandler.cs
│ │ ├── GenericPipelineBehavior.cs
│ │ ├── GenericRequestPostProcessor.cs
│ │ ├── GenericRequestPreProcessor.cs
│ │ ├── Jing.cs
│ │ ├── JingHandler.cs
│ │ ├── MediatR.Examples.csproj
│ │ ├── Ping.cs
│ │ ├── PingHandler.cs
│ │ ├── Pinged.cs
│ │ ├── PingedHandler.cs
│ │ ├── Pong.cs
│ │ ├── Ponged.cs
│ │ ├── Runner.cs
│ │ └── Streams/
│ │ ├── GenericStreamPipelineBehavior.cs
│ │ ├── Sing.cs
│ │ ├── SingHandler.cs
│ │ └── Song.cs
│ ├── MediatR.Examples.AspNetCore/
│ │ ├── MediatR.Examples.AspNetCore.csproj
│ │ └── Program.cs
│ ├── MediatR.Examples.Autofac/
│ │ ├── MediatR.Examples.Autofac.csproj
│ │ └── Program.cs
│ ├── MediatR.Examples.DryIoc/
│ │ ├── MediatR.Examples.DryIoc.csproj
│ │ └── Program.cs
│ ├── MediatR.Examples.Lamar/
│ │ ├── MediatR.Examples.Lamar.csproj
│ │ └── Program.cs
│ ├── MediatR.Examples.LightInject/
│ │ ├── MediatR.Examples.LightInject.csproj
│ │ └── Program.cs
│ ├── MediatR.Examples.PublishStrategies/
│ │ ├── AsyncPingedHandler.cs
│ │ ├── CustomMediator.cs
│ │ ├── MediatR.Examples.PublishStrategies.csproj
│ │ ├── Program.cs
│ │ ├── PublishStrategy.cs
│ │ ├── Publisher.cs
│ │ └── SyncPingedHandler.cs
│ ├── MediatR.Examples.SimpleInjector/
│ │ ├── MediatR.Examples.SimpleInjector.csproj
│ │ └── Program.cs
│ ├── MediatR.Examples.Stashbox/
│ │ ├── MediatR.Examples.Stashbox.csproj
│ │ └── Program.cs
│ └── MediatR.Examples.Windsor/
│ ├── ContravariantFilter.cs
│ ├── MediatR.Examples.Windsor.csproj
│ └── Program.cs
├── src/
│ ├── MediatR/
│ │ ├── Entities/
│ │ │ └── OpenBehavior.cs
│ │ ├── IMediator.cs
│ │ ├── INotificationHandler.cs
│ │ ├── INotificationPublisher.cs
│ │ ├── IPipelineBehavior.cs
│ │ ├── IPublisher.cs
│ │ ├── IRequestHandler.cs
│ │ ├── ISender.cs
│ │ ├── IStreamPipelineBehavior.cs
│ │ ├── IStreamRequestHandler.cs
│ │ ├── Internal/
│ │ │ ├── HandlersOrderer.cs
│ │ │ └── ObjectDetails.cs
│ │ ├── Licensing/
│ │ │ ├── BuildInfo.cs
│ │ │ ├── Edition.cs
│ │ │ ├── License.cs
│ │ │ ├── LicenseAccessor.cs
│ │ │ ├── LicenseValidator.cs
│ │ │ └── ProductType.cs
│ │ ├── MediatR.csproj
│ │ ├── Mediator.cs
│ │ ├── MicrosoftExtensionsDI/
│ │ │ ├── MediatRServiceCollectionExtensions.cs
│ │ │ ├── MediatrServiceConfiguration.cs
│ │ │ └── RequestExceptionActionProcessorStrategy.cs
│ │ ├── NotificationHandlerExecutor.cs
│ │ ├── NotificationPublishers/
│ │ │ ├── ForeachAwaitPublisher.cs
│ │ │ └── TaskWhenAllPublisher.cs
│ │ ├── Pipeline/
│ │ │ ├── IRequestExceptionAction.cs
│ │ │ ├── IRequestExceptionHandler.cs
│ │ │ ├── IRequestPostProcessor.cs
│ │ │ ├── IRequestPreProcessor.cs
│ │ │ ├── RequestExceptionActionProcessorBehavior.cs
│ │ │ ├── RequestExceptionHandlerState.cs
│ │ │ ├── RequestExceptionProcessorBehavior.cs
│ │ │ ├── RequestPostProcessorBehavior.cs
│ │ │ └── RequestPreProcessorBehavior.cs
│ │ ├── Registration/
│ │ │ └── ServiceRegistrar.cs
│ │ ├── TypeForwardings.cs
│ │ ├── Wrappers/
│ │ │ ├── NotificationHandlerWrapper.cs
│ │ │ ├── RequestHandlerWrapper.cs
│ │ │ └── StreamRequestHandlerWrapper.cs
│ │ └── license.txt
│ └── MediatR.Contracts/
│ ├── INotification.cs
│ ├── IRequest.cs
│ ├── IStreamRequest.cs
│ ├── MediatR.Contracts.csproj
│ └── Unit.cs
└── test/
├── MediatR.Benchmarks/
│ ├── Benchmarks.cs
│ ├── DotTraceDiagnoser.cs
│ ├── GenericPipelineBehavior.cs
│ ├── GenericRequestPostProcessor.cs
│ ├── GenericRequestPreProcessor.cs
│ ├── MediatR.Benchmarks.csproj
│ ├── Ping.cs
│ ├── Pinged.cs
│ └── Program.cs
├── MediatR.DependencyInjectionTests/
│ ├── Abstractions/
│ │ ├── BaseAssemblyResolutionTests.cs
│ │ └── BaseServiceProviderFixture.cs
│ ├── AutoFacDependencyInjectionTests.cs
│ ├── Contracts/
│ │ ├── Notifications/
│ │ │ └── Ding.cs
│ │ ├── Requests/
│ │ │ ├── InternalPing.cs
│ │ │ ├── InternalVoidPing.cs
│ │ │ ├── PrivatePing.cs
│ │ │ ├── PrivateVoidPing.cs
│ │ │ ├── PublicPing.cs
│ │ │ └── PublicVoidPing.cs
│ │ ├── Responses/
│ │ │ └── Pong.cs
│ │ └── StreamRequests/
│ │ ├── InternalZing.cs
│ │ ├── PrivateZing.cs
│ │ └── PublicZing.cs
│ ├── DryIocDependencyInjectionTests.cs
│ ├── LamarDependencyInjectionTests.cs
│ ├── LightInjectDependencyInjectionTests.cs
│ ├── MediatR.DependencyInjectionTests.csproj
│ ├── MicrosoftDependencyInjectionTests.cs
│ ├── Providers/
│ │ ├── AutoFacServiceProviderFixture.cs
│ │ ├── DryIocServiceProviderFixture.cs
│ │ ├── LamarServiceProviderFixture.cs
│ │ ├── LightInjectServiceProviderFixture.cs
│ │ ├── MicrosoftServiceProviderFixture.cs
│ │ └── StashBoxServiceProviderFixture.cs
│ ├── StashBoxDependencyInjectionTests.cs
│ └── Usings.cs
└── MediatR.Tests/
├── CreateStreamTests.cs
├── ExceptionTests.cs
├── GenericRequestHandlerTests.cs
├── GenericTypeConstraintsTests.cs
├── GlobalUsings.cs
├── Licensing/
│ └── LicenseValidatorTests.cs
├── MediatR.Tests.csproj
├── MicrosoftExtensionsDI/
│ ├── AssemblyResolutionTests.cs
│ ├── BaseGenericRequestHandlerTests.cs
│ ├── CustomMediatorTests.cs
│ ├── DerivingRequestsTests.cs
│ ├── DuplicateAssemblyResolutionTests.cs
│ ├── Handlers.cs
│ ├── Issue1118Tests.cs
│ ├── NotificationPublisherTests.cs
│ ├── PipeLineMultiCallToConstructorTest.cs
│ ├── PipelineTests.cs
│ ├── StreamPipelineTests.cs
│ ├── TypeEvaluatorTests.cs
│ └── TypeResolutionTests.cs
├── NotificationHandlerTests.cs
├── NotificationPublisherTests.cs
├── Pipeline/
│ ├── RequestExceptionActionTests.cs
│ ├── RequestExceptionHandlerTests.cs
│ ├── RequestPostProcessorTests.cs
│ ├── RequestPreProcessorTests.cs
│ └── Streams/
│ └── StreamPipelineBehaviorTests.cs
├── PipelineTests.cs
├── PublishTests.cs
├── SendTests.cs
├── SendVoidInterfaceTests.cs
├── ServiceFactoryTests.cs
├── StreamPipelineTests.cs
├── TestContainer.cs
└── UnitTests.cs
================================================
FILE CONTENTS
================================================
================================================
FILE: .editorconfig
================================================
root=true
; EditorConfig helps developers define and maintain consistent
; coding styles between different editors and IDEs.
; For more visit http://editorconfig.org.
; Choose between lf or rf on "end_of_line" property
[*.proto]
indent_style=tab
indent_size=tab
tab_width=4
[*.{asax,ascx,aspx,cs,cshtml,css,htm,html,js,jsx,master,razor,skin,ts,tsx,vb,xaml,xamlx,xoml}]
indent_style=space
indent_size=4
tab_width=4
[*.{appxmanifest,build,config,csproj,dbml,discomap,dtd,json,jsproj,lsproj,njsproj,nuspec,proj,props,resjson,resw,resx,StyleCop,targets,tasks,vbproj,xml,xsd}]
indent_style=space
indent_size=2
tab_width=2
[*]
# Standard properties
end_of_line=native
insert_final_newline=false
# Microsoft .NET properties
csharp_indent_braces=false
csharp_indent_switch_labels=true
csharp_new_line_before_catch=true
csharp_new_line_before_else=true
csharp_new_line_before_finally=true
csharp_new_line_before_members_in_object_initializers=false
csharp_new_line_before_open_brace=all
csharp_new_line_between_query_expression_clauses=true
csharp_preferred_modifier_order=public, private, protected, internal, new, abstract, virtual, sealed, override, static, readonly, extern, unsafe, volatile, async:suggestion
csharp_preserve_single_line_blocks=true
csharp_space_after_cast=true
csharp_space_after_colon_in_inheritance_clause=true
csharp_space_after_comma=true
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_before_colon_in_inheritance_clause=true
csharp_space_before_comma=false
csharp_space_before_dot=false
csharp_space_before_open_square_brackets=false
csharp_space_before_semicolon_in_for_statement=false
csharp_space_between_empty_square_brackets=false
csharp_space_between_method_call_empty_parameter_list_parentheses=false
csharp_space_between_method_call_name_and_opening_parenthesis=false
csharp_space_between_method_call_parameter_list_parentheses=false
csharp_space_between_method_declaration_empty_parameter_list_parentheses=false
csharp_space_between_method_declaration_name_and_open_parenthesis=false
csharp_space_between_method_declaration_parameter_list_parentheses=false
csharp_space_between_parentheses=false
csharp_space_between_square_brackets=false
csharp_style_expression_bodied_accessors=true:suggestion
csharp_style_expression_bodied_constructors=true:suggestion
csharp_style_expression_bodied_methods=true:suggestion
csharp_style_expression_bodied_properties=true:suggestion
csharp_style_var_elsewhere=true:hint
csharp_style_var_for_built_in_types=true:hint
csharp_style_var_when_type_is_apparent=true:hint
csharp_using_directive_placement=outside_namespace:silent
dotnet_style_predefined_type_for_locals_parameters_members=true:hint
dotnet_style_predefined_type_for_member_access=true:hint
dotnet_style_qualification_for_event=false:hint
dotnet_style_qualification_for_field=false:hint
dotnet_style_qualification_for_method=false:hint
dotnet_style_qualification_for_property=false:hint
dotnet_style_require_accessibility_modifiers=for_non_interface_members:hint
================================================
FILE: .gitattributes
================================================
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
*.jpg binary
*.png binary
*.gif binary
core.eol crlf
*.cs diff=csharp
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
*.sln merge=union
*.slnx merge=union
================================================
FILE: .github/workflows/ci.yml
================================================
name: CI
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
env:
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
MINVERBUILDMETADATA: build.${{ github.run_id }}.${{ github.run_attempt}}
permissions:
id-token: write
contents: read
checks: write
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4.2.0
with:
fetch-depth: 0
filter: tree:0
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
- name: Install NuGetKeyVaultSignTool
run: dotnet tool install --global NuGetKeyVaultSignTool
- name: Build and Test
run: ./Build.ps1
shell: pwsh
- name: Report Test Results
uses: dorny/test-reporter@v1.9.1
if: success() || failure()
with:
name: Test Results (Windows)
path: '**/TestResults/**/*.trx'
reporter: dotnet-trx
- name: Get package version
id: version
shell: pwsh
run: |
$pkg = Get-ChildItem ./artifacts -Filter "MediatR.*.nupkg" | Select-Object -First 1
$version = $pkg.BaseName -replace '^MediatR\.', ''
"version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
- name: Generate SBOM
shell: pwsh
run: |
dotnet tool install --global Microsoft.Sbom.DotNetTool
sbom-tool generate `
-b ./artifacts `
-bc ./src/MediatR `
-pn MediatR `
-pv ${{ steps.version.outputs.version }} `
-ps "Lucky Penny Software LLC" `
-nsb https://mediatr.io
- name: Push to MyGet
if: github.ref == 'refs/heads/main'
env:
NUGET_URL: https://f.feedz.io/lucky-penny-software/mediatr/nuget/index.json
NUGET_API_KEY: ${{ secrets.FEEDZIO_ACCESS_TOKEN }}
run: ./Push.ps1
shell: pwsh
- name: Artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts
path: artifacts/**/*
================================================
FILE: .github/workflows/release.yml
================================================
name: Release
on:
push:
tags:
- '*.*.*'
env:
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
MINVERBUILDMETADATA: build.${{ github.run_id }}.${{ github.run_attempt}}
permissions:
id-token: write
contents: read
checks: write
jobs:
build:
strategy:
matrix:
os: [windows-2025]
fail-fast: false
runs-on: windows-2025
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
filter: tree:0
- name: Azure Login via OIDC
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
- name: Install NuGetKeyVaultSignTool
run: dotnet tool install --global NuGetKeyVaultSignTool
- name: Build and Test
run: ./Build.ps1
shell: pwsh
- name: Report Test Results
uses: dorny/test-reporter@v1.9.1
if: always()
with:
name: Test Results (Windows)
path: '**/TestResults/**/*.trx'
reporter: dotnet-trx
- name: Get package version
id: version
shell: pwsh
run: |
$pkg = Get-ChildItem ./artifacts -Filter "MediatR.*.nupkg" | Select-Object -First 1
$version = $pkg.BaseName -replace '^MediatR\.', ''
"version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
- name: Generate SBOM
shell: pwsh
run: |
dotnet tool install --global Microsoft.Sbom.DotNetTool
sbom-tool generate `
-b ./artifacts `
-bc ./src/MediatR `
-pn MediatR `
-pv ${{ steps.version.outputs.version }} `
-ps "Lucky Penny Software LLC" `
-nsb https://mediatr.io
- name: Sign packages
run: |-
foreach ($f in Get-ChildItem "./artifacts" -Filter "*.nupkg") {
NuGetKeyVaultSignTool sign $f.FullName --file-digest sha256 --timestamp-rfc3161 http://timestamp.digicert.com --azure-key-vault-managed-identity --azure-key-vault-url ${{ secrets.AZURE_KEYVAULT_URI }} --azure-key-vault-certificate ${{ secrets.CODESIGN_CERT_NAME }}
}
- name: Push to MyGet
env:
NUGET_URL: https://f.feedz.io/lucky-penny-software/mediatr/nuget/index.json
NUGET_API_KEY: ${{ secrets.FEEDZIO_ACCESS_TOKEN }}
run: ./Push.ps1
shell: pwsh
- name: Push to NuGet
env:
NUGET_URL: https://api.nuget.org/v3/index.json
NUGET_API_KEY: ${{ secrets.MEDIATR_NUGET_API_KEY }}
run: ./Push.ps1
shell: pwsh
- name: Artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts
path: artifacts/**/*
================================================
FILE: .github/workflows/triage-issues.yml
================================================
# https://github.com/actions/stale
name: "Stale issue & PR handler"
on:
workflow_dispatch:
schedule:
- cron: "0 12 * * *"
env:
ISSUES_DAYS_BEFORE_CLOSE: 14
PR_DAYS_BEFORE_CLOSE: 14
ISSUES_DAYS_BEFORE_STALE: 60
PR_DAYS_BEFORE_STALE: 28
jobs:
issues:
name: "Close stale issues and PRs"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/stale@v6.0.0"
with:
stale-issue-label: "stale"
stale-issue-message: "This issue is stale because it has been open ${{ env.ISSUES_DAYS_BEFORE_STALE }} days with no activity. Remove stale label or comment or this will be closed in ${{ env.ISSUES_DAYS_BEFORE_CLOSE }} days."
close-issue-message: 'This issue was closed because it has been stalled for ${{ env.ISSUES_DAYS_BEFORE_CLOSE }} days with no activity.'
days-before-close: "${{ env.ISSUES_DAYS_BEFORE_CLOSE }}"
days-before-stale: "${{ env.ISSUES_DAYS_BEFORE_STALE }}"
exempt-issue-assignees: true
exempt-issue-labels: 'awaiting-approval,work-in-progress,up-for-grabs'
stale-pr-label: "stale"
stale-pr-message: 'This PR is stale because it has been open ${{ env.PR_DAYS_BEFORE_STALE }} days with no activity. Remove stale label or comment or this will be closed in ${{ env.PR_DAYS_BEFORE_CLOSE }} days.'
close-pr-message: 'This PR was closed because it has been stalled for ${{ env.PR_DAYS_BEFORE_CLOSE }} days with no activity.'
days-before-pr-close: "${{ env.PR_DAYS_BEFORE_CLOSE }}"
days-before-pr-stale: "${{ env.PR_DAYS_BEFORE_STALE }}"
exempt-all-pr-assignees: true
exempt-pr-labels: 'awaiting-approval,work-in-progress'
================================================
FILE: .gitignore
================================================
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
artifacts/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
*.ncrunchsolution
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# Windows Azure Build Output
csx/
*.build.csdef
# Windows Store app package directory
AppPackages/
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Project Rider
*.iml
.idea
# Apple
.DS_Store
================================================
FILE: Build.ps1
================================================
# Taken from psake https://github.com/psake/psake
<#
.SYNOPSIS
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
to see if an error occcured. If an error is detected then an exception is thrown.
This function allows you to run command-line programs without having to
explicitly check the $lastexitcode variable.
.EXAMPLE
exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
#>
function Exec
{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
)
& $cmd
if ($lastexitcode -ne 0) {
throw ("Exec: " + $errorMessage)
}
}
$artifacts = ".\artifacts"
if(Test-Path $artifacts) { Remove-Item $artifacts -Force -Recurse }
exec { & dotnet clean -c Release }
exec { & dotnet build -c Release }
exec { & dotnet test -c Release --no-build -l trx --verbosity=normal }
exec { & dotnet pack .\src\MediatR\MediatR.csproj -c Release -o $artifacts --no-build }
================================================
FILE: BuildContracts.ps1
================================================
# Taken from psake https://github.com/psake/psake
<#
.SYNOPSIS
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
to see if an error occcured. If an error is detected then an exception is thrown.
This function allows you to run command-line programs without having to
explicitly check the $lastexitcode variable.
.EXAMPLE
exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
#>
function Exec
{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
)
& $cmd
if ($lastexitcode -ne 0) {
throw ("Exec: " + $errorMessage)
}
}
$artifacts = ".\artifacts"
$contracts = ".\src\MediatR.Contracts\MediatR.Contracts.csproj"
if(Test-Path $artifacts) { Remove-Item $artifacts -Force -Recurse }
exec { & dotnet clean $contracts -c Release }
exec { & dotnet build $contracts -c Release -p:ContinuousIntegrationBuild=true }
exec { & dotnet pack $contracts -c Release -o $artifacts --no-build }
================================================
FILE: Directory.Build.props
================================================
<Project>
<PropertyGroup>
<IsMac>$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::get_OSX())))</IsMac>
<IsWindows>$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::get_Windows())))</IsWindows>
<LangVersion>13.0</LangVersion>
<NoWarn>$(NoWarn);CS1701;CS1702;CS1591;NU1900</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
</Project>
================================================
FILE: LICENSE.md
================================================
By accessing code under the [Lucky Penny Software GitHub Organization](https://github.com/LuckyPennySoftware) (Lucky Penny Software) here, you are agreeing to the following licensing terms.
If you do not agree to these terms, do not access Lucky Penny Software code.
Your license to Lucky Penny Software source code and/or binaries is governed by the Reciprocal Public License 1.5 (RPL1.5) license as described here:
https://opensource.org/license/rpl-1-5/
If you do not wish to release the source of software you build using Lucky Penny Software source code and/or binaries under the terms above, you may use Lucky Penny Software source code and/or binaries under the License Agreement described here:
https://luckypennysoftware.com/license
================================================
FILE: MediatR.slnx
================================================
<Solution>
<Folder Name="/samples/">
<Project Path="samples/MediatR.Examples.AspNetCore/MediatR.Examples.AspNetCore.csproj" />
<Project Path="samples/MediatR.Examples.Autofac/MediatR.Examples.Autofac.csproj" />
<Project Path="samples/MediatR.Examples.DryIoc/MediatR.Examples.DryIoc.csproj" />
<Project Path="samples/MediatR.Examples.Lamar/MediatR.Examples.Lamar.csproj" />
<Project Path="samples/MediatR.Examples.LightInject/MediatR.Examples.LightInject.csproj" />
<Project Path="samples/MediatR.Examples.PublishStrategies/MediatR.Examples.PublishStrategies.csproj" />
<Project Path="samples/MediatR.Examples.SimpleInjector/MediatR.Examples.SimpleInjector.csproj" />
<Project Path="samples/MediatR.Examples.Stashbox/MediatR.Examples.Stashbox.csproj" />
<Project Path="samples/MediatR.Examples/MediatR.Examples.csproj" />
</Folder>
<Folder Name="/Solution Items/">
<File Path=".editorconfig" />
<File Path=".github/workflows/ci.yml" />
<File Path=".github/workflows/release.yml" />
<File Path="Build.ps1" />
<File Path="BuildContracts.ps1" />
<File Path="Directory.Build.props" />
<File Path="MediatR.snk" />
<File Path="Push.ps1" />
<File Path="README.md" />
</Folder>
<Folder Name="/src/">
<Project Path="src/MediatR.Contracts/MediatR.Contracts.csproj" />
<Project Path="src/MediatR/MediatR.csproj" />
</Folder>
<Folder Name="/test/">
<Project Path="test/MediatR.Benchmarks/MediatR.Benchmarks.csproj" />
<Project Path="test/MediatR.DependencyInjectionTests/MediatR.DependencyInjectionTests.csproj" />
<Project Path="test/MediatR.Tests/MediatR.Tests.csproj" />
</Folder>
</Solution>
================================================
FILE: NuGet.Config
================================================
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
================================================
FILE: Push.ps1
================================================
$scriptName = $MyInvocation.MyCommand.Name
$artifacts = "./artifacts"
if ([string]::IsNullOrEmpty($Env:NUGET_API_KEY)) {
Write-Host "${scriptName}: NUGET_API_KEY is empty or not set. Skipped pushing package(s)."
} else {
Get-ChildItem $artifacts -Filter "*.nupkg" | ForEach-Object {
Write-Host "$($scriptName): Pushing $($_.Name)"
dotnet nuget push $_ --source $Env:NUGET_URL --api-key $Env:NUGET_API_KEY --skip-duplicate
if ($lastexitcode -ne 0) {
throw ("Exec: " + $errorMessage)
}
}
}
================================================
FILE: README.md
================================================
MediatR
=======

[](https://www.nuget.org/packages/mediatr)
[](https://www.nuget.org/packages/mediatr)
[](https://myget.org/gallery/mediatr-ci)
Simple mediator implementation in .NET
In-process messaging with no dependencies.
Supports request/response, commands, queries, notifications and events, synchronous and async with intelligent dispatching via C# generic variance.
Examples in the [wiki](https://github.com/LuckyPennySoftware/MediatR/wiki).
### Installing MediatR
You should install [MediatR with NuGet](https://www.nuget.org/packages/MediatR):
Install-Package MediatR
Or via the .NET Core command line interface:
dotnet add package MediatR
Either commands, from Package Manager Console or .NET Core CLI, will download and install MediatR and all required dependencies.
### Using Contracts-Only Package
To reference only the contracts for MediatR, which includes:
- `IRequest` (including generic variants)
- `INotification`
- `IStreamRequest`
Add a package reference to [MediatR.Contracts](https://www.nuget.org/packages/MediatR.Contracts)
This package is useful in scenarios where your MediatR contracts are in a separate assembly/project from handlers. Example scenarios include:
- API contracts
- GRPC contracts
- Blazor
### Registering with `IServiceCollection`
MediatR supports `Microsoft.Extensions.DependencyInjection.Abstractions` directly. To register various MediatR services and handlers:
```
services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblyContaining<Startup>());
```
or with an assembly:
```
services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Startup).Assembly));
```
This registers:
- `IMediator` as transient
- `ISender` as transient
- `IPublisher` as transient
- `IRequestHandler<,>` concrete implementations as transient
- `IRequestHandler<>` concrete implementations as transient
- `INotificationHandler<>` concrete implementations as transient
- `IStreamRequestHandler<>` concrete implementations as transient
- `IRequestExceptionHandler<,,>` concrete implementations as transient
- `IRequestExceptionAction<,>)` concrete implementations as transient
This also registers open generic implementations for:
- `INotificationHandler<>`
- `IRequestExceptionHandler<,,>`
- `IRequestExceptionAction<,>`
To register behaviors, stream behaviors, pre/post processors:
```csharp
services.AddMediatR(cfg => {
cfg.RegisterServicesFromAssembly(typeof(Startup).Assembly);
cfg.AddBehavior<PingPongBehavior>();
cfg.AddStreamBehavior<PingPongStreamBehavior>();
cfg.AddRequestPreProcessor<PingPreProcessor>();
cfg.AddRequestPostProcessor<PingPongPostProcessor>();
cfg.AddOpenBehavior(typeof(GenericBehavior<,>));
});
```
With additional methods for open generics and overloads for explicit service types.
### Setting the license key
You can set the license key when registering MediatR:
```csharp
services.AddMediatR(cfg =>
{
cfg.LicenseKey = "<license key here>";
})
```
Or if not using Microsoft.Extensions.DependencyInjection:
```csharp
Mediator.LicenseKey = "<license key here>";
```
> [!TIP]
> The license key does not need to be set on client applications (such as Blazor WASM).
> Turn off the license warning by configuring logging in your logging start configuration:
> `builder.Logging.AddFilter("LuckyPennySoftware.MediatR.License", LogLevel.None);`
You can register for your license key at [MediatR.io](https://mediatr.io)
================================================
FILE: samples/MediatR.Examples/ConstrainedRequestPostProcessor.cs
================================================
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MediatR.Pipeline;
namespace MediatR.Examples;
public class ConstrainedRequestPostProcessor<TRequest, TResponse>
: IRequestPostProcessor<TRequest, TResponse>
where TRequest : Ping
{
private readonly TextWriter _writer;
public ConstrainedRequestPostProcessor(TextWriter writer)
{
_writer = writer;
}
public Task Process(TRequest request, TResponse response, CancellationToken cancellationToken)
{
return _writer.WriteLineAsync("- All Done with Ping");
}
}
================================================
FILE: samples/MediatR.Examples/ExceptionHandler/Exceptions.cs
================================================
using System;
namespace MediatR.Examples.ExceptionHandler;
public class ConnectionException : Exception { }
public class ForbiddenException : ConnectionException { }
public class ResourceNotFoundException : ConnectionException { }
public class ServerException : Exception { }
================================================
FILE: samples/MediatR.Examples/ExceptionHandler/ExceptionsHandlers.cs
================================================
using MediatR.Pipeline;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR.Examples.ExceptionHandler;
public class CommonExceptionHandler : IRequestExceptionHandler<PingResource, Pong, Exception>
{
private readonly TextWriter _writer;
public CommonExceptionHandler(TextWriter writer) => _writer = writer;
public async Task Handle(PingResource request,
Exception exception,
RequestExceptionHandlerState<Pong> state,
CancellationToken cancellationToken)
{
// Exception type name must be written in messages by LogExceptionAction before
// Exception handler type name required because it is checked later in messages
await _writer.WriteLineAsync($"---- Exception Handler: '{typeof(CommonExceptionHandler).FullName}'").ConfigureAwait(false);
state.SetHandled(new Pong());
}
}
public class ConnectionExceptionHandler : IRequestExceptionHandler<PingResource, Pong, ConnectionException>
{
private readonly TextWriter _writer;
public ConnectionExceptionHandler(TextWriter writer) => _writer = writer;
public async Task Handle(PingResource request,
ConnectionException exception,
RequestExceptionHandlerState<Pong> state,
CancellationToken cancellationToken)
{
// Exception type name must be written in messages by LogExceptionAction before
// Exception handler type name required because it is checked later in messages
await _writer.WriteLineAsync($"---- Exception Handler: '{typeof(ConnectionExceptionHandler).FullName}'").ConfigureAwait(false);
state.SetHandled(new Pong());
}
}
public class AccessDeniedExceptionHandler : IRequestExceptionHandler<PingResource, Pong, ForbiddenException>
{
private readonly TextWriter _writer;
public AccessDeniedExceptionHandler(TextWriter writer) => _writer = writer;
public async Task Handle(PingResource request,
ForbiddenException exception,
RequestExceptionHandlerState<Pong> state,
CancellationToken cancellationToken)
{
// Exception type name must be written in messages by LogExceptionAction before
// Exception handler type name required because it is checked later in messages
await _writer.WriteLineAsync($"---- Exception Handler: '{typeof(AccessDeniedExceptionHandler).FullName}'").ConfigureAwait(false);
state.SetHandled(new Pong());
}
}
public class ServerExceptionHandler : IRequestExceptionHandler<PingNewResource, Pong, ServerException>
{
private readonly TextWriter _writer;
public ServerExceptionHandler(TextWriter writer) => _writer = writer;
public virtual async Task Handle(PingNewResource request,
ServerException exception,
RequestExceptionHandlerState<Pong> state,
CancellationToken cancellationToken)
{
// Exception type name must be written in messages by LogExceptionAction before
// Exception handler type name required because it is checked later in messages
await _writer.WriteLineAsync($"---- Exception Handler: '{typeof(ServerExceptionHandler).FullName}'").ConfigureAwait(false);
state.SetHandled(new Pong());
}
}
================================================
FILE: samples/MediatR.Examples/ExceptionHandler/ExceptionsHandlersOverrides.cs
================================================
using MediatR.Pipeline;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR.Examples.ExceptionHandler.Overrides;
public class CommonExceptionHandler : IRequestExceptionHandler<PingResourceTimeout, Pong, Exception>
{
private readonly TextWriter _writer;
public CommonExceptionHandler(TextWriter writer) => _writer = writer;
public async Task Handle(PingResourceTimeout request,
Exception exception,
RequestExceptionHandlerState<Pong> state,
CancellationToken cancellationToken)
{
// Exception type name must be written in messages by LogExceptionAction before
// Exception handler type name required because it is checked later in messages
await _writer.WriteLineAsync($"---- Exception Handler: '{typeof(CommonExceptionHandler).FullName}'").ConfigureAwait(false);
state.SetHandled(new Pong());
}
}
public class ServerExceptionHandler : ExceptionHandler.ServerExceptionHandler
{
private readonly TextWriter _writer;
public ServerExceptionHandler(TextWriter writer) : base(writer) => _writer = writer;
public override async Task Handle(PingNewResource request,
ServerException exception,
RequestExceptionHandlerState<Pong> state,
CancellationToken cancellationToken)
{
// Exception type name must be written in messages by LogExceptionAction before
// Exception handler type name required because it is checked later in messages
await _writer.WriteLineAsync($"---- Exception Handler: '{typeof(ServerExceptionHandler).FullName}'").ConfigureAwait(false);
state.SetHandled(new Pong());
}
}
================================================
FILE: samples/MediatR.Examples/ExceptionHandler/Handlers.cs
================================================
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR.Examples.ExceptionHandler;
public class PingResourceHandler : IRequestHandler<PingResource, Pong>
{
private readonly TextWriter _writer;
public PingResourceHandler(TextWriter writer) => _writer = writer;
public Task<Pong> Handle(PingResource request, CancellationToken cancellationToken)
{
throw new ResourceNotFoundException();
}
}
public class PingNewResourceHandler : IRequestHandler<PingNewResource, Pong>
{
private readonly TextWriter _writer;
public PingNewResourceHandler(TextWriter writer) => _writer = writer;
public Task<Pong> Handle(PingNewResource request, CancellationToken cancellationToken)
{
throw new ServerException();
}
}
public class PingResourceTimeoutHandler : IRequestHandler<PingResourceTimeout, Pong>
{
private readonly TextWriter _writer;
public PingResourceTimeoutHandler(TextWriter writer) => _writer = writer;
public Task<Pong> Handle(PingResourceTimeout request, CancellationToken cancellationToken)
{
throw new TaskCanceledException();
}
}
public class PingResourceTimeoutOverrideHandler : IRequestHandler<Overrides.PingResourceTimeout, Pong>
{
private readonly TextWriter _writer;
public PingResourceTimeoutOverrideHandler(TextWriter writer) => _writer = writer;
public Task<Pong> Handle(Overrides.PingResourceTimeout request, CancellationToken cancellationToken)
{
throw new TaskCanceledException();
}
}
public class PingProtectedResourceHandler : IRequestHandler<PingProtectedResource, Pong>
{
private readonly TextWriter _writer;
public PingProtectedResourceHandler(TextWriter writer) => _writer = writer;
public Task<Pong> Handle(PingProtectedResource request, CancellationToken cancellationToken)
{
throw new ForbiddenException();
}
}
================================================
FILE: samples/MediatR.Examples/ExceptionHandler/LogExceptionAction.cs
================================================
using MediatR.Pipeline;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR.Examples.ExceptionHandler;
public class LogExceptionAction : IRequestExceptionAction<Ping, Exception>
{
private readonly TextWriter _writer;
public LogExceptionAction(TextWriter writer) => _writer = writer;
public Task Execute(Ping request, Exception exception, CancellationToken cancellationToken)
=> _writer.WriteLineAsync($"--- Exception: '{exception.GetType().FullName}'");
}
================================================
FILE: samples/MediatR.Examples/ExceptionHandler/Requests.cs
================================================
namespace MediatR.Examples.ExceptionHandler;
public class PingResource : Ping { }
public class PingNewResource : Ping { }
public class PingResourceTimeout : PingResource { }
public class PingProtectedResource : PingResource { }
================================================
FILE: samples/MediatR.Examples/ExceptionHandler/RequestsOverrides.cs
================================================
namespace MediatR.Examples.ExceptionHandler.Overrides;
public class PingResourceTimeout : ExceptionHandler.PingResourceTimeout { }
================================================
FILE: samples/MediatR.Examples/GenericHandler.cs
================================================
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR.Examples;
public class GenericHandler : INotificationHandler<INotification>
{
private readonly TextWriter _writer;
public GenericHandler(TextWriter writer)
{
_writer = writer;
}
public Task Handle(INotification notification, CancellationToken cancellationToken)
{
return _writer.WriteLineAsync("Got notified.");
}
}
================================================
FILE: samples/MediatR.Examples/GenericPipelineBehavior.cs
================================================
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR.Examples;
public class GenericPipelineBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
private readonly TextWriter _writer;
public GenericPipelineBehavior(TextWriter writer)
{
_writer = writer;
}
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
await _writer.WriteLineAsync("-- Handling Request");
var response = await next();
await _writer.WriteLineAsync("-- Finished Request");
return response;
}
}
================================================
FILE: samples/MediatR.Examples/GenericRequestPostProcessor.cs
================================================
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MediatR.Pipeline;
namespace MediatR.Examples;
public class GenericRequestPostProcessor<TRequest, TResponse> : IRequestPostProcessor<TRequest, TResponse>
{
private readonly TextWriter _writer;
public GenericRequestPostProcessor(TextWriter writer)
{
_writer = writer;
}
public Task Process(TRequest request, TResponse response, CancellationToken cancellationToken)
{
return _writer.WriteLineAsync("- All Done");
}
}
================================================
FILE: samples/MediatR.Examples/GenericRequestPreProcessor.cs
================================================
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MediatR.Pipeline;
namespace MediatR.Examples;
public class GenericRequestPreProcessor<TRequest> : IRequestPreProcessor<TRequest>
{
private readonly TextWriter _writer;
public GenericRequestPreProcessor(TextWriter writer)
{
_writer = writer;
}
public Task Process(TRequest request, CancellationToken cancellationToken)
{
return _writer.WriteLineAsync("- Starting Up");
}
}
================================================
FILE: samples/MediatR.Examples/Jing.cs
================================================
namespace MediatR.Examples;
public class Jing : IRequest
{
public string Message { get; set; }
}
================================================
FILE: samples/MediatR.Examples/JingHandler.cs
================================================
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR.Examples;
public class JingHandler : IRequestHandler<Jing>
{
private readonly TextWriter _writer;
public JingHandler(TextWriter writer)
{
_writer = writer;
}
public Task Handle(Jing request, CancellationToken cancellationToken)
{
return _writer.WriteLineAsync($"--- Handled Jing: {request.Message}, no Jong");
}
}
================================================
FILE: samples/MediatR.Examples/MediatR.Examples.csproj
================================================
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MediatR\MediatR.csproj" />
</ItemGroup>
</Project>
================================================
FILE: samples/MediatR.Examples/Ping.cs
================================================
namespace MediatR.Examples;
public class Ping : IRequest<Pong>
{
public string Message { get; set; }
}
================================================
FILE: samples/MediatR.Examples/PingHandler.cs
================================================
using System.IO;
using System.Threading;
namespace MediatR.Examples;
using System.Threading.Tasks;
public class PingHandler : IRequestHandler<Ping, Pong>
{
private readonly TextWriter _writer;
public PingHandler(TextWriter writer)
{
_writer = writer;
}
public async Task<Pong> Handle(Ping request, CancellationToken cancellationToken)
{
await _writer.WriteLineAsync($"--- Handled Ping: {request.Message}");
return new Pong { Message = request.Message + " Pong" };
}
}
================================================
FILE: samples/MediatR.Examples/Pinged.cs
================================================
namespace MediatR.Examples;
public class Pinged : INotification
{
}
================================================
FILE: samples/MediatR.Examples/PingedHandler.cs
================================================
using System.Threading;
namespace MediatR.Examples;
using System.IO;
using System.Threading.Tasks;
public class PingedHandler : INotificationHandler<Pinged>
{
private readonly TextWriter _writer;
public PingedHandler(TextWriter writer)
{
_writer = writer;
}
public Task Handle(Pinged notification, CancellationToken cancellationToken)
{
return _writer.WriteLineAsync("Got pinged async.");
}
}
public class PongedHandler : INotificationHandler<Ponged>
{
private readonly TextWriter _writer;
public PongedHandler(TextWriter writer)
{
_writer = writer;
}
public Task Handle(Ponged notification, CancellationToken cancellationToken)
{
return _writer.WriteLineAsync("Got ponged async.");
}
}
public class ConstrainedPingedHandler<TNotification> : INotificationHandler<TNotification>
where TNotification : Pinged
{
private readonly TextWriter _writer;
public ConstrainedPingedHandler(TextWriter writer)
{
_writer = writer;
}
public Task Handle(TNotification notification, CancellationToken cancellationToken)
{
return _writer.WriteLineAsync("Got pinged constrained async.");
}
}
public class PingedAlsoHandler : INotificationHandler<Pinged>
{
private readonly TextWriter _writer;
public PingedAlsoHandler(TextWriter writer)
{
_writer = writer;
}
public Task Handle(Pinged notification, CancellationToken cancellationToken)
{
return _writer.WriteLineAsync("Got pinged also async.");
}
}
================================================
FILE: samples/MediatR.Examples/Pong.cs
================================================
namespace MediatR.Examples;
public class Pong
{
public string Message { get; set; }
}
================================================
FILE: samples/MediatR.Examples/Ponged.cs
================================================
namespace MediatR.Examples;
public class Ponged : INotification
{
}
================================================
FILE: samples/MediatR.Examples/Runner.cs
================================================
using System;
using System.Linq;
using System.Text;
namespace MediatR.Examples;
using MediatR.Examples.ExceptionHandler;
using System.IO;
using System.Threading.Tasks;
public static class Runner
{
public static async Task Run(IMediator mediator, WrappingWriter writer, string projectName, bool testStreams = false)
{
await writer.WriteLineAsync("===============");
await writer.WriteLineAsync(projectName);
await writer.WriteLineAsync("===============");
await writer.WriteLineAsync();
await writer.WriteLineAsync("Sending Ping...");
var pong = await mediator.Send(new Ping { Message = "Ping" });
await writer.WriteLineAsync("Received: " + pong.Message);
await writer.WriteLineAsync();
await writer.WriteLineAsync("Publishing Pinged...");
await mediator.Publish(new Pinged());
await writer.WriteLineAsync();
await writer.WriteLineAsync("Publishing Ponged...");
var failedPong = false;
try
{
await mediator.Publish(new Ponged());
}
catch (Exception e)
{
failedPong = true;
await writer.WriteLineAsync(e.ToString());
}
await writer.WriteLineAsync();
var failedJing = false;
await writer.WriteLineAsync("Sending Jing...");
try
{
await mediator.Send(new Jing { Message = "Jing" });
}
catch (Exception e)
{
failedJing = true;
await writer.WriteLineAsync(e.ToString());
}
await writer.WriteLineAsync();
bool failedSing = false;
if (testStreams)
{
await writer.WriteLineAsync("Sending Sing...");
try
{
int i = 0;
await foreach (Song s in mediator.CreateStream(new Sing { Message = "Sing" }))
{
if (i == 0) {
failedSing = !(s.Message.Contains("Singing do"));
}
else if (i == 1)
{
failedSing = !(s.Message.Contains("Singing re"));
}
else if (i == 2)
{
failedSing = !(s.Message.Contains("Singing mi"));
}
else if (i == 3)
{
failedSing = !(s.Message.Contains("Singing fa"));
}
else if (i == 4)
{
failedSing = !(s.Message.Contains("Singing so"));
}
else if (i == 5)
{
failedSing = !(s.Message.Contains("Singing la"));
}
else if (i == 6)
{
failedSing = !(s.Message.Contains("Singing ti"));
}
else if (i == 7)
{
failedSing = !(s.Message.Contains("Singing do"));
}
failedSing = failedSing || (++i) > 10;
}
}
catch (Exception e)
{
failedSing = true;
await writer.WriteLineAsync(e.ToString());
}
await writer.WriteLineAsync();
}
var isHandlerForSameExceptionWorks = await IsHandlerForSameExceptionWorks(mediator, writer).ConfigureAwait(false);
var isHandlerForBaseExceptionWorks = await IsHandlerForBaseExceptionWorks(mediator, writer).ConfigureAwait(false);
var isHandlerForLessSpecificExceptionWorks = await IsHandlerForLessSpecificExceptionWorks(mediator, writer).ConfigureAwait(false);
var isPreferredHandlerForBaseExceptionWorks = await IsPreferredHandlerForBaseExceptionWorks(mediator, writer).ConfigureAwait(false);
var isOverriddenHandlerForBaseExceptionWorks = await IsOverriddenHandlerForBaseExceptionWorks(mediator, writer).ConfigureAwait(false);
await writer.WriteLineAsync("---------------");
var contents = writer.Contents;
var order = new[] {
contents.IndexOf("- Starting Up", StringComparison.OrdinalIgnoreCase),
contents.IndexOf("-- Handling Request", StringComparison.OrdinalIgnoreCase),
contents.IndexOf("--- Handled Ping", StringComparison.OrdinalIgnoreCase),
contents.IndexOf("-- Finished Request", StringComparison.OrdinalIgnoreCase),
contents.IndexOf("- All Done", StringComparison.OrdinalIgnoreCase),
contents.IndexOf("- All Done with Ping", StringComparison.OrdinalIgnoreCase),
};
var streamOrder = new[] {
contents.IndexOf("-- Handling StreamRequest", StringComparison.OrdinalIgnoreCase),
contents.IndexOf("--- Handled Sing: Sing, Song", StringComparison.OrdinalIgnoreCase),
contents.IndexOf("-- Finished StreamRequest", StringComparison.OrdinalIgnoreCase),
};
var results = new RunResults
{
RequestHandlers = contents.Contains("--- Handled Ping:"),
VoidRequestsHandlers = contents.Contains("--- Handled Jing:"),
PipelineBehaviors = contents.Contains("-- Handling Request"),
RequestPreProcessors = contents.Contains("- Starting Up"),
RequestPostProcessors = contents.Contains("- All Done"),
ConstrainedGenericBehaviors = contents.Contains("- All Done with Ping") && !failedJing,
OrderedPipelineBehaviors = order.SequenceEqual(order.OrderBy(i => i)),
NotificationHandler = contents.Contains("Got pinged async"),
MultipleNotificationHandlers = contents.Contains("Got pinged async") && contents.Contains("Got pinged also async"),
ConstrainedGenericNotificationHandler = contents.Contains("Got pinged constrained async") && !failedPong,
CovariantNotificationHandler = contents.Contains("Got notified"),
HandlerForSameException = isHandlerForSameExceptionWorks,
HandlerForBaseException = isHandlerForBaseExceptionWorks,
HandlerForLessSpecificException = isHandlerForLessSpecificExceptionWorks,
PreferredHandlerForBaseException = isPreferredHandlerForBaseExceptionWorks,
OverriddenHandlerForBaseException = isOverriddenHandlerForBaseExceptionWorks,
// Streams
StreamRequestHandlers = contents.Contains("--- Handled Sing: Sing, Song") && !failedSing,
StreamPipelineBehaviors = contents.Contains("-- Handling StreamRequest"),
StreamOrderedPipelineBehaviors = streamOrder.SequenceEqual(streamOrder.OrderBy(i => i))
};
await writer.WriteLineAsync($"Request Handler....................................................{(results.RequestHandlers ? "Y" : "N")}");
await writer.WriteLineAsync($"Void Request Handler...............................................{(results.VoidRequestsHandlers ? "Y" : "N")}");
await writer.WriteLineAsync($"Pipeline Behavior..................................................{(results.PipelineBehaviors ? "Y" : "N")}");
await writer.WriteLineAsync($"Pre-Processor......................................................{(results.RequestPreProcessors ? "Y" : "N")}");
await writer.WriteLineAsync($"Post-Processor.....................................................{(results.RequestPostProcessors ? "Y" : "N")}");
await writer.WriteLineAsync($"Constrained Post-Processor.........................................{(results.ConstrainedGenericBehaviors ? "Y" : "N")}");
await writer.WriteLineAsync($"Ordered Behaviors..................................................{(results.OrderedPipelineBehaviors ? "Y" : "N")}");
await writer.WriteLineAsync($"Notification Handler...............................................{(results.NotificationHandler ? "Y" : "N")}");
await writer.WriteLineAsync($"Notification Handlers..............................................{(results.MultipleNotificationHandlers ? "Y" : "N")}");
await writer.WriteLineAsync($"Constrained Notification Handler...................................{(results.ConstrainedGenericNotificationHandler ? "Y" : "N")}");
await writer.WriteLineAsync($"Covariant Notification Handler.....................................{(results.CovariantNotificationHandler ? "Y" : "N")}");
await writer.WriteLineAsync($"Handler for inherited request with same exception used.............{(results.HandlerForSameException ? "Y" : "N")}");
await writer.WriteLineAsync($"Handler for inherited request with base exception used.............{(results.HandlerForBaseException ? "Y" : "N")}");
await writer.WriteLineAsync($"Handler for request with less specific exception used by priority..{(results.HandlerForLessSpecificException ? "Y" : "N")}");
await writer.WriteLineAsync($"Preferred handler for inherited request with base exception used...{(results.PreferredHandlerForBaseException ? "Y" : "N")}");
await writer.WriteLineAsync($"Overridden handler for inherited request with same exception used..{(results.OverriddenHandlerForBaseException ? "Y" : "N")}");
if (testStreams)
{
await writer.WriteLineAsync($"Stream Request Handler.............................................{(results.StreamRequestHandlers ? "Y" : "N")}");
await writer.WriteLineAsync($"Stream Pipeline Behavior...........................................{(results.StreamPipelineBehaviors ? "Y" : "N")}");
await writer.WriteLineAsync($"Stream Ordered Behaviors...........................................{(results.StreamOrderedPipelineBehaviors ? "Y" : "N")}");
}
await writer.WriteLineAsync();
}
private static async Task<bool> IsHandlerForSameExceptionWorks(IMediator mediator, WrappingWriter writer)
{
var isHandledCorrectly = false;
await writer.WriteLineAsync("Checking handler to catch exact exception...");
try
{
await mediator.Send(new PingProtectedResource { Message = "Ping to protected resource" });
isHandledCorrectly = IsExceptionHandledBy<ForbiddenException, AccessDeniedExceptionHandler>(writer);
}
catch (Exception e)
{
await writer.WriteLineAsync(e.Message);
}
await writer.WriteLineAsync();
return isHandledCorrectly;
}
private static async Task<bool> IsHandlerForBaseExceptionWorks(IMediator mediator, WrappingWriter writer)
{
var isHandledCorrectly = false;
await writer.WriteLineAsync("Checking shared handler to catch exception by base type...");
try
{
await mediator.Send(new PingResource { Message = "Ping to missed resource" });
isHandledCorrectly = IsExceptionHandledBy<ResourceNotFoundException, ConnectionExceptionHandler>(writer);
}
catch (Exception e)
{
await writer.WriteLineAsync(e.Message);
}
await writer.WriteLineAsync();
return isHandledCorrectly;
}
private static async Task<bool> IsHandlerForLessSpecificExceptionWorks(IMediator mediator, WrappingWriter writer)
{
var isHandledCorrectly = false;
await writer.WriteLineAsync("Checking base handler to catch any exception...");
try
{
await mediator.Send(new PingResourceTimeout { Message = "Ping to ISS resource" });
isHandledCorrectly = IsExceptionHandledBy<TaskCanceledException, CommonExceptionHandler> (writer);
}
catch (Exception e)
{
await writer.WriteLineAsync(e.Message);
}
await writer.WriteLineAsync();
return isHandledCorrectly;
}
private static async Task<bool> IsPreferredHandlerForBaseExceptionWorks(IMediator mediator, WrappingWriter writer)
{
var isHandledCorrectly = false;
await writer.WriteLineAsync("Selecting preferred handler to handle exception...");
try
{
await mediator.Send(new ExceptionHandler.Overrides.PingResourceTimeout { Message = "Ping to ISS resource (preferred)" });
isHandledCorrectly = IsExceptionHandledBy<TaskCanceledException, ExceptionHandler.Overrides.CommonExceptionHandler> (writer);
}
catch (Exception e)
{
await writer.WriteLineAsync(e.Message);
}
await writer.WriteLineAsync();
return isHandledCorrectly;
}
private static async Task<bool> IsOverriddenHandlerForBaseExceptionWorks(IMediator mediator, WrappingWriter writer)
{
var isHandledCorrectly = false;
await writer.WriteLineAsync("Selecting new handler to handle exception...");
try
{
await mediator.Send(new PingNewResource { Message = "Ping to ISS resource (override)" });
isHandledCorrectly = IsExceptionHandledBy<ServerException, ExceptionHandler.Overrides.ServerExceptionHandler> (writer);
}
catch (Exception e)
{
await writer.WriteLineAsync(e.Message);
}
await writer.WriteLineAsync();
return isHandledCorrectly;
}
private static bool IsExceptionHandledBy<TException, THandler>(WrappingWriter writer)
where TException : Exception
{
var messages = writer.Contents.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None).ToList();
if (messages.Count - 3 < 0)
return false;
// Note: For this handler type to be found in messages, it must be written in messages by LogExceptionAction
return messages[messages.Count - 2].Contains(typeof(THandler).FullName)
// Note: For this exception type to be found in messages, exception must be written in all tested exception handlers
&& messages[messages.Count - 3].Contains(typeof(TException).FullName);
}
}
public class RunResults
{
public bool RequestHandlers { get; set; }
public bool VoidRequestsHandlers { get; set; }
public bool PipelineBehaviors { get; set; }
public bool RequestPreProcessors { get; set; }
public bool RequestPostProcessors { get; set; }
public bool OrderedPipelineBehaviors { get; set; }
public bool ConstrainedGenericBehaviors { get; set; }
public bool NotificationHandler { get; set; }
public bool MultipleNotificationHandlers { get; set; }
public bool CovariantNotificationHandler { get; set; }
public bool ConstrainedGenericNotificationHandler { get; set; }
public bool HandlerForSameException { get; set; }
public bool HandlerForBaseException { get; set; }
public bool HandlerForLessSpecificException { get; set; }
public bool PreferredHandlerForBaseException { get; set; }
public bool OverriddenHandlerForBaseException { get; set; }
// Stream results
public bool StreamRequestHandlers { get; set; }
public bool StreamPipelineBehaviors { get; set; }
public bool StreamOrderedPipelineBehaviors { get; set; }
}
public class WrappingWriter : TextWriter
{
private readonly TextWriter _innerWriter;
private readonly StringBuilder _stringWriter = new StringBuilder();
public WrappingWriter(TextWriter innerWriter)
{
_innerWriter = innerWriter;
}
public override void Write(char value)
{
_stringWriter.Append(value);
_innerWriter.Write(value);
}
public override Task WriteLineAsync(string value)
{
_stringWriter.AppendLine(value);
return _innerWriter.WriteLineAsync(value);
}
public override Encoding Encoding => _innerWriter.Encoding;
public string Contents => _stringWriter.ToString();
}
================================================
FILE: samples/MediatR.Examples/Streams/GenericStreamPipelineBehavior.cs
================================================
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR.Examples;
public class GenericStreamPipelineBehavior<TRequest, TResponse> : IStreamPipelineBehavior<TRequest, TResponse>
{
private readonly TextWriter _writer;
public GenericStreamPipelineBehavior(TextWriter writer)
{
_writer = writer;
}
public async IAsyncEnumerable<TResponse> Handle(TRequest request, StreamHandlerDelegate<TResponse> next, [EnumeratorCancellation]CancellationToken cancellationToken)
{
await _writer.WriteLineAsync("-- Handling StreamRequest");
await foreach (var response in next().WithCancellation(cancellationToken).ConfigureAwait(false))
{
yield return response;
}
await _writer.WriteLineAsync("-- Finished StreamRequest");
}
}
================================================
FILE: samples/MediatR.Examples/Streams/Sing.cs
================================================
namespace MediatR.Examples;
public class Sing : IStreamRequest<Song>
{
public string Message { get; set; }
}
================================================
FILE: samples/MediatR.Examples/Streams/SingHandler.cs
================================================
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR.Examples;
public class SingHandler : IStreamRequestHandler<Sing, Song>
{
private readonly TextWriter _writer;
public SingHandler(TextWriter writer)
{
_writer = writer;
}
public async IAsyncEnumerable<Song> Handle(Sing request, [EnumeratorCancellation]CancellationToken cancellationToken)
{
await _writer.WriteLineAsync($"--- Handled Sing: {request.Message}, Song");
yield return await Task.Run(() => new Song { Message = request.Message + "ing do" });
yield return await Task.Run(() => new Song { Message = request.Message + "ing re" });
yield return await Task.Run(() => new Song { Message = request.Message + "ing mi" });
yield return await Task.Run(() => new Song { Message = request.Message + "ing fa" });
yield return await Task.Run(() => new Song { Message = request.Message + "ing so" });
yield return await Task.Run(() => new Song { Message = request.Message + "ing la" });
yield return await Task.Run(() => new Song { Message = request.Message + "ing ti" });
yield return await Task.Run(() => new Song { Message = request.Message + "ing do" });
}
}
================================================
FILE: samples/MediatR.Examples/Streams/Song.cs
================================================
namespace MediatR.Examples;
public class Song
{
public string Message { get; set; }
}
================================================
FILE: samples/MediatR.Examples.AspNetCore/MediatR.Examples.AspNetCore.csproj
================================================
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MediatR.Examples\MediatR.Examples.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
</ItemGroup>
</Project>
================================================
FILE: samples/MediatR.Examples.AspNetCore/Program.cs
================================================
using System;
using System.IO;
using System.Threading.Tasks;
using MediatR.Pipeline;
using Microsoft.Extensions.DependencyInjection;
namespace MediatR.Examples.AspNetCore;
public static class Program
{
public static Task Main(string[] args)
{
var writer = new WrappingWriter(Console.Out);
var mediator = BuildMediator(writer);
return Runner.Run(mediator, writer, "ASP.NET Core DI", testStreams: true);
}
private static IMediator BuildMediator(WrappingWriter writer)
{
var services = new ServiceCollection();
services.AddSingleton<TextWriter>(writer);
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssemblies(typeof(Ping).Assembly, typeof(Sing).Assembly);
});
services.AddScoped(typeof(IStreamRequestHandler<Sing, Song>), typeof(SingHandler));
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(GenericPipelineBehavior<,>));
services.AddScoped(typeof(IRequestPreProcessor<>), typeof(GenericRequestPreProcessor<>));
services.AddScoped(typeof(IRequestPostProcessor<,>), typeof(GenericRequestPostProcessor<,>));
services.AddScoped(typeof(IStreamPipelineBehavior<,>), typeof(GenericStreamPipelineBehavior<,>));
var provider = services.BuildServiceProvider();
return provider.GetRequiredService<IMediator>();
}
}
================================================
FILE: samples/MediatR.Examples.Autofac/MediatR.Examples.Autofac.csproj
================================================
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MediatR.Examples\MediatR.Examples.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="8.4.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
</ItemGroup>
</Project>
================================================
FILE: samples/MediatR.Examples.Autofac/Program.cs
================================================
using Autofac.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
namespace MediatR.Examples.Autofac;
using global::Autofac;
using MediatR.Pipeline;
using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
internal static class Program
{
public static Task Main(string[] args)
{
var writer = new WrappingWriter(Console.Out);
var mediator = BuildMediator(writer);
return Runner.Run(mediator, writer, "Autofac", testStreams: true);
}
private static IMediator BuildMediator(WrappingWriter writer)
{
var builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(typeof(IMediator).GetTypeInfo().Assembly).AsImplementedInterfaces();
var mediatrOpenTypes = new[]
{
typeof(IRequestHandler<,>),
typeof(IRequestExceptionHandler<,,>),
typeof(IRequestExceptionAction<,>),
typeof(INotificationHandler<>),
typeof(IStreamRequestHandler<,>)
};
foreach (var mediatrOpenType in mediatrOpenTypes)
{
builder
.RegisterAssemblyTypes(typeof(Ping).GetTypeInfo().Assembly)
.AsClosedTypesOf(mediatrOpenType)
// when having a single class implementing several handler types
// this call will cause a handler to be called twice
// in general you should try to avoid having a class implementing for instance `IRequestHandler<,>` and `INotificationHandler<>`
// the other option would be to remove this call
// see also https://github.com/LuckyPennySoftware/MediatR/issues/462
.AsImplementedInterfaces();
}
builder.RegisterInstance(writer).As<TextWriter>();
// It appears Autofac returns the last registered types first
builder.RegisterGeneric(typeof(GenericStreamPipelineBehavior<,>)).As(typeof(IStreamPipelineBehavior<,>));
builder.RegisterGeneric(typeof(RequestPostProcessorBehavior<,>)).As(typeof(IPipelineBehavior<,>));
builder.RegisterGeneric(typeof(RequestPreProcessorBehavior<,>)).As(typeof(IPipelineBehavior<,>));
builder.RegisterGeneric(typeof(RequestExceptionActionProcessorBehavior<,>))
.As(typeof(IPipelineBehavior<,>));
builder.RegisterGeneric(typeof(RequestExceptionProcessorBehavior<,>)).As(typeof(IPipelineBehavior<,>));
builder.RegisterGeneric(typeof(GenericRequestPreProcessor<>)).As(typeof(IRequestPreProcessor<>));
builder.RegisterGeneric(typeof(GenericRequestPostProcessor<,>)).As(typeof(IRequestPostProcessor<,>));
builder.RegisterGeneric(typeof(GenericPipelineBehavior<,>)).As(typeof(IPipelineBehavior<,>));
builder.RegisterGeneric(typeof(ConstrainedRequestPostProcessor<,>)).As(typeof(IRequestPostProcessor<,>));
builder.RegisterGeneric(typeof(ConstrainedPingedHandler<>)).As(typeof(INotificationHandler<>));
var services = new ServiceCollection();
builder.Populate(services);
// The below returns:
// - RequestPreProcessorBehavior
// - RequestPostProcessorBehavior
// - GenericPipelineBehavior
// - GenericStreamPipelineBehavior
// - RequestExceptionActionProcessorBehavior
// - RequestExceptionProcessorBehavior
//var behaviors = container
// .Resolve<IEnumerable<IPipelineBehavior<Ping, Pong>>>()
// .ToList();
var container = builder.Build();
var serviceProvider = new AutofacServiceProvider(container);
var mediator = serviceProvider.GetRequiredService<IMediator>();
return mediator;
}
}
================================================
FILE: samples/MediatR.Examples.DryIoc/MediatR.Examples.DryIoc.csproj
================================================
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MediatR.Examples\MediatR.Examples.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DryIoc.Microsoft.DependencyInjection" Version="8.0.0-preview-04" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
</ItemGroup>
</Project>
================================================
FILE: samples/MediatR.Examples.DryIoc/Program.cs
================================================
using System;
using System.IO;
using System.Threading.Tasks;
using DryIoc;
using DryIoc.Microsoft.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
namespace MediatR.Examples.DryIoc;
class Program
{
static Task Main()
{
var writer = new WrappingWriter(Console.Out);
var mediator = BuildMediator(writer);
return Runner.Run(mediator, writer, "DryIoc");
}
private static IMediator BuildMediator(WrappingWriter writer)
{
var container = new Container();
// Since Mediator has multiple constructors, consider adding rule to allow that
// var container = new Container(rules => rules.With(FactoryMethod.ConstructorWithResolvableArguments))
container.Use<TextWriter>(writer);
//Pipeline works out of the box here
container.RegisterMany(new[] { typeof(IMediator).GetAssembly(), typeof(Ping).GetAssembly() }, Registrator.Interfaces);
//Without the container having FactoryMethod.ConstructorWithResolvableArguments commented above
//You must select the desired constructor
container.Register<IMediator, Mediator>(made: Made.Of(() => new Mediator(Arg.Of<IServiceProvider>())));
var services = new ServiceCollection();
var adapterContainer = container.WithDependencyInjectionAdapter(services);
return adapterContainer.GetRequiredService<IMediator>();
}
}
================================================
FILE: samples/MediatR.Examples.Lamar/MediatR.Examples.Lamar.csproj
================================================
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Lamar" Version="15.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MediatR.Examples\MediatR.Examples.csproj" />
</ItemGroup>
</Project>
================================================
FILE: samples/MediatR.Examples.Lamar/Program.cs
================================================
using System;
using System.IO;
using System.Threading.Tasks;
using Lamar;
using MediatR.Pipeline;
namespace MediatR.Examples.Lamar;
class Program
{
static Task Main(string[] args)
{
var writer = new WrappingWriter(Console.Out);
var mediator = BuildMediator(writer);
return Runner.Run(mediator, writer, "Lamar");
}
private static IMediator BuildMediator(WrappingWriter writer)
{
var container = new Container(cfg =>
{
cfg.Scan(scanner =>
{
scanner.AssemblyContainingType<Ping>();
scanner.ConnectImplementationsToTypesClosing(typeof(IRequestHandler<,>));
scanner.ConnectImplementationsToTypesClosing(typeof(INotificationHandler<>));
scanner.ConnectImplementationsToTypesClosing(typeof(IRequestExceptionAction<,>));
scanner.ConnectImplementationsToTypesClosing(typeof(IRequestExceptionHandler<,,>));
});
//Pipeline
cfg.For(typeof(IPipelineBehavior<,>)).Add(typeof(RequestExceptionProcessorBehavior<,>));
cfg.For(typeof(IPipelineBehavior<,>)).Add(typeof(RequestExceptionActionProcessorBehavior<,>));
cfg.For(typeof(IPipelineBehavior<,>)).Add(typeof(RequestPreProcessorBehavior<,>));
cfg.For(typeof(IPipelineBehavior<,>)).Add(typeof(RequestPostProcessorBehavior<,>));
cfg.For(typeof(IPipelineBehavior<,>)).Add(typeof(GenericPipelineBehavior<,>));
cfg.For(typeof(IRequestPreProcessor<>)).Add(typeof(GenericRequestPreProcessor<>));
cfg.For(typeof(IRequestPostProcessor<,>)).Add(typeof(GenericRequestPostProcessor<,>));
cfg.For(typeof(IRequestPostProcessor<,>)).Add(typeof(ConstrainedRequestPostProcessor<,>));
//Constrained notification handlers
cfg.For(typeof(INotificationHandler<>)).Add(typeof(ConstrainedPingedHandler<>));
// This is the default but let's be explicit. At most we should be container scoped.
cfg.For<IMediator>().Use<Mediator>().Transient();
cfg.For<TextWriter>().Use(writer);
});
var mediator = container.GetInstance<IMediator>();
return mediator;
}
}
================================================
FILE: samples/MediatR.Examples.LightInject/MediatR.Examples.LightInject.csproj
================================================
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MediatR.Examples\MediatR.Examples.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="LightInject" Version="7.0.1" />
<PackageReference Include="LightInject.Microsoft.DependencyInjection" Version="4.0.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
</ItemGroup>
</Project>
================================================
FILE: samples/MediatR.Examples.LightInject/Program.cs
================================================
using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using LightInject;
using LightInject.Microsoft.DependencyInjection;
using MediatR.Pipeline;
using Microsoft.Extensions.DependencyInjection;
namespace MediatR.Examples.LightInject;
class Program
{
static Task Main(string[] args)
{
var writer = new WrappingWriter(Console.Out);
var mediator = BuildMediator(writer);
return Runner.Run(mediator, writer, "LightInject");
}
private static IMediator BuildMediator(WrappingWriter writer)
{
var serviceContainer = new ServiceContainer(ContainerOptions.Default.WithMicrosoftSettings());
serviceContainer.Register<IMediator, Mediator>();
serviceContainer.RegisterInstance<TextWriter>(writer);
serviceContainer.RegisterAssembly(typeof(Ping).GetTypeInfo().Assembly, (serviceType, implementingType) =>
serviceType.IsConstructedGenericType &&
(
serviceType.GetGenericTypeDefinition() == typeof(IRequestHandler<,>) ||
serviceType.GetGenericTypeDefinition() == typeof(INotificationHandler<>)
));
serviceContainer.RegisterOrdered(typeof(IPipelineBehavior<,>),
new[]
{
typeof(RequestPreProcessorBehavior<,>),
typeof(RequestPostProcessorBehavior<,>),
typeof(GenericPipelineBehavior<,>)
}, type => null);
serviceContainer.RegisterOrdered(typeof(IRequestPostProcessor<,>),
new[]
{
typeof(GenericRequestPostProcessor<,>),
typeof(ConstrainedRequestPostProcessor<,>)
}, type => null);
serviceContainer.Register(typeof(IRequestPreProcessor<>), typeof(GenericRequestPreProcessor<>));
var services = new ServiceCollection();
var provider = serviceContainer.CreateServiceProvider(services);
return provider.GetRequiredService<IMediator>();
}
}
================================================
FILE: samples/MediatR.Examples.PublishStrategies/AsyncPingedHandler.cs
================================================
using System;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR.Examples.PublishStrategies;
public class AsyncPingedHandler : INotificationHandler<Pinged>
{
public AsyncPingedHandler(string name)
{
Name = name;
}
public string Name { get; set; }
public async Task Handle(Pinged notification, CancellationToken cancellationToken)
{
if (Name == "2")
{
throw new ArgumentException("Name cannot be '2'");
}
Console.WriteLine($"[AsyncPingedHandler {Name}] {DateTime.Now:HH:mm:ss.fff} : Pinged");
await Task.Delay(100).ConfigureAwait(false);
Console.WriteLine($"[AsyncPingedHandler {Name}] {DateTime.Now:HH:mm:ss.fff} : After pinged");
}
}
================================================
FILE: samples/MediatR.Examples.PublishStrategies/CustomMediator.cs
================================================
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR.Examples.PublishStrategies;
public class CustomMediator : Mediator
{
private readonly Func<IEnumerable<NotificationHandlerExecutor>, INotification, CancellationToken, Task> _publish;
public CustomMediator(IServiceProvider serviceFactory, Func<IEnumerable<NotificationHandlerExecutor>, INotification, CancellationToken, Task> publish) : base(serviceFactory)
=> _publish = publish;
protected override Task PublishCore(IEnumerable<NotificationHandlerExecutor> handlerExecutors, INotification notification, CancellationToken cancellationToken)
=> _publish(handlerExecutors, notification, cancellationToken);
}
================================================
FILE: samples/MediatR.Examples.PublishStrategies/MediatR.Examples.PublishStrategies.csproj
================================================
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MediatR\MediatR.csproj" />
<ProjectReference Include="..\MediatR.Examples\MediatR.Examples.csproj" />
</ItemGroup>
</Project>
================================================
FILE: samples/MediatR.Examples.PublishStrategies/Program.cs
================================================
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
namespace MediatR.Examples.PublishStrategies;
class Program
{
static async Task Main(string[] args)
{
var services = new ServiceCollection();
services.AddSingleton<Publisher>();
services.AddTransient<INotificationHandler<Pinged>>(sp => new SyncPingedHandler("1"));
services.AddTransient<INotificationHandler<Pinged>>(sp => new AsyncPingedHandler("2"));
services.AddTransient<INotificationHandler<Pinged>>(sp => new AsyncPingedHandler("3"));
services.AddTransient<INotificationHandler<Pinged>>(sp => new SyncPingedHandler("4"));
var provider = services.BuildServiceProvider();
var publisher = provider.GetRequiredService<Publisher>();
var pinged = new Pinged();
foreach (PublishStrategy strategy in Enum.GetValues(typeof(PublishStrategy)))
{
Console.WriteLine($"Strategy: {strategy}");
Console.WriteLine("----------");
try
{
await publisher.Publish(pinged, strategy);
}
catch (Exception ex)
{
Console.WriteLine($"{ex.GetType()}: {ex.Message}");
}
await Task.Delay(1000);
Console.WriteLine("----------");
}
Console.WriteLine("done");
}
}
================================================
FILE: samples/MediatR.Examples.PublishStrategies/PublishStrategy.cs
================================================
namespace MediatR.Examples.PublishStrategies;
/// <summary>
/// Strategy to use when publishing notifications
/// </summary>
public enum PublishStrategy
{
/// <summary>
/// Run each notification handler after one another. Returns when all handlers are finished. In case of any exception(s), they will be captured in an AggregateException.
/// </summary>
SyncContinueOnException = 0,
/// <summary>
/// Run each notification handler after one another. Returns when all handlers are finished or an exception has been thrown. In case of an exception, any handlers after that will not be run.
/// </summary>
SyncStopOnException = 1,
/// <summary>
/// Run all notification handlers asynchronously. Returns when all handlers are finished. In case of any exception(s), they will be captured in an AggregateException.
/// </summary>
Async = 2,
/// <summary>
/// Run each notification handler on its own thread using Task.Run(). Returns immediately and does not wait for any handlers to finish. Note that you cannot capture any exceptions, even if you await the call to Publish.
/// </summary>
ParallelNoWait = 3,
/// <summary>
/// Run each notification handler on its own thread using Task.Run(). Returns when all threads (handlers) are finished. In case of any exception(s), they are captured in an AggregateException by Task.WhenAll.
/// </summary>
ParallelWhenAll = 4,
/// <summary>
/// Run each notification handler on its own thread using Task.Run(). Returns when any thread (handler) is finished. Note that you cannot capture any exceptions (See msdn documentation of Task.WhenAny)
/// </summary>
ParallelWhenAny = 5,
}
================================================
FILE: samples/MediatR.Examples.PublishStrategies/Publisher.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR.Examples.PublishStrategies;
public class Publisher
{
private readonly IServiceProvider _serviceFactory;
public Publisher(IServiceProvider serviceFactory)
{
_serviceFactory = serviceFactory;
PublishStrategies[PublishStrategy.Async] = new CustomMediator(_serviceFactory, AsyncContinueOnException);
PublishStrategies[PublishStrategy.ParallelNoWait] = new CustomMediator(_serviceFactory, ParallelNoWait);
PublishStrategies[PublishStrategy.ParallelWhenAll] = new CustomMediator(_serviceFactory, ParallelWhenAll);
PublishStrategies[PublishStrategy.ParallelWhenAny] = new CustomMediator(_serviceFactory, ParallelWhenAny);
PublishStrategies[PublishStrategy.SyncContinueOnException] = new CustomMediator(_serviceFactory, SyncContinueOnException);
PublishStrategies[PublishStrategy.SyncStopOnException] = new CustomMediator(_serviceFactory, SyncStopOnException);
}
public IDictionary<PublishStrategy, IMediator> PublishStrategies = new Dictionary<PublishStrategy, IMediator>();
public PublishStrategy DefaultStrategy { get; set; } = PublishStrategy.SyncContinueOnException;
public Task Publish<TNotification>(TNotification notification)
{
return Publish(notification, DefaultStrategy, default(CancellationToken));
}
public Task Publish<TNotification>(TNotification notification, PublishStrategy strategy)
{
return Publish(notification, strategy, default(CancellationToken));
}
public Task Publish<TNotification>(TNotification notification, CancellationToken cancellationToken)
{
return Publish(notification, DefaultStrategy, cancellationToken);
}
public Task Publish<TNotification>(TNotification notification, PublishStrategy strategy, CancellationToken cancellationToken)
{
if (!PublishStrategies.TryGetValue(strategy, out var mediator))
{
throw new ArgumentException($"Unknown strategy: {strategy}");
}
return mediator.Publish(notification, cancellationToken);
}
private Task ParallelWhenAll(IEnumerable<NotificationHandlerExecutor> handlers, INotification notification, CancellationToken cancellationToken)
{
var tasks = new List<Task>();
foreach (var handler in handlers)
{
tasks.Add(Task.Run(() => handler.HandlerCallback(notification, cancellationToken)));
}
return Task.WhenAll(tasks);
}
private Task ParallelWhenAny(IEnumerable<NotificationHandlerExecutor> handlers, INotification notification, CancellationToken cancellationToken)
{
var tasks = new List<Task>();
foreach (var handler in handlers)
{
tasks.Add(Task.Run(() => handler.HandlerCallback(notification, cancellationToken)));
}
return Task.WhenAny(tasks);
}
private Task ParallelNoWait(IEnumerable<NotificationHandlerExecutor> handlers, INotification notification, CancellationToken cancellationToken)
{
foreach (var handler in handlers)
{
Task.Run(() => handler.HandlerCallback(notification, cancellationToken));
}
return Task.CompletedTask;
}
private async Task AsyncContinueOnException(IEnumerable<NotificationHandlerExecutor> handlers, INotification notification, CancellationToken cancellationToken)
{
var tasks = new List<Task>();
var exceptions = new List<Exception>();
foreach (var handler in handlers)
{
try
{
tasks.Add(handler.HandlerCallback(notification, cancellationToken));
}
catch (Exception ex) when (!(ex is OutOfMemoryException || ex is StackOverflowException))
{
exceptions.Add(ex);
}
}
try
{
await Task.WhenAll(tasks).ConfigureAwait(false);
}
catch (AggregateException ex)
{
exceptions.AddRange(ex.Flatten().InnerExceptions);
}
catch (Exception ex) when (!(ex is OutOfMemoryException || ex is StackOverflowException))
{
exceptions.Add(ex);
}
if (exceptions.Any())
{
throw new AggregateException(exceptions);
}
}
private async Task SyncStopOnException(IEnumerable<NotificationHandlerExecutor> handlers, INotification notification, CancellationToken cancellationToken)
{
foreach (var handler in handlers)
{
await handler.HandlerCallback(notification, cancellationToken).ConfigureAwait(false);
}
}
private async Task SyncContinueOnException(IEnumerable<NotificationHandlerExecutor> handlers, INotification notification, CancellationToken cancellationToken)
{
var exceptions = new List<Exception>();
foreach (var handler in handlers)
{
try
{
await handler.HandlerCallback(notification, cancellationToken).ConfigureAwait(false);
}
catch (AggregateException ex)
{
exceptions.AddRange(ex.Flatten().InnerExceptions);
}
catch (Exception ex) when (!(ex is OutOfMemoryException || ex is StackOverflowException))
{
exceptions.Add(ex);
}
}
if (exceptions.Any())
{
throw new AggregateException(exceptions);
}
}
}
================================================
FILE: samples/MediatR.Examples.PublishStrategies/SyncPingedHandler.cs
================================================
using System;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR.Examples.PublishStrategies;
public class SyncPingedHandler : INotificationHandler<Pinged>
{
public SyncPingedHandler(string name)
{
Name = name;
}
public string Name { get; set; }
public Task Handle(Pinged notification, CancellationToken cancellationToken)
{
if (Name == "2")
{
throw new ArgumentException("Name cannot be '2'");
}
Console.WriteLine($"[SyncPingedHandler {Name}] {DateTime.Now:HH:mm:ss.fff} : Pinged");
Thread.Sleep(100);
Console.WriteLine($"[SyncPingedHandler {Name}] {DateTime.Now:HH:mm:ss.fff} : After pinged");
return Task.CompletedTask;
}
}
================================================
FILE: samples/MediatR.Examples.SimpleInjector/MediatR.Examples.SimpleInjector.csproj
================================================
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MediatR.Examples\MediatR.Examples.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SimpleInjector" Version="5.5.0" />
<PackageReference Include="SimpleInjector.Integration.ServiceCollection" Version="5.5.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
</ItemGroup>
</Project>
================================================
FILE: samples/MediatR.Examples.SimpleInjector/Program.cs
================================================
using System.IO;
using System.Threading.Tasks;
using MediatR.Pipeline;
using Microsoft.Extensions.DependencyInjection;
namespace MediatR.Examples.SimpleInjector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using global::SimpleInjector;
internal static class Program
{
private static Task Main(string[] args)
{
var writer = new WrappingWriter(Console.Out);
var mediator = BuildMediator(writer);
return Runner.Run(mediator, writer, "SimpleInjector", true);
}
private static IMediator BuildMediator(WrappingWriter writer)
{
var container = new Container();
var services = new ServiceCollection();
services
.AddSimpleInjector(container);
var assemblies = GetAssemblies().ToArray();
container.RegisterSingleton<IMediator, Mediator>();
container.Register(typeof(IRequestHandler<,>), assemblies);
RegisterHandlers(container, typeof(INotificationHandler<>), assemblies);
RegisterHandlers(container, typeof(IRequestExceptionAction<,>), assemblies);
RegisterHandlers(container, typeof(IRequestExceptionHandler<,,>), assemblies);
RegisterHandlers(container, typeof(IStreamRequestHandler<,>), assemblies);
container.Register(() => (TextWriter) writer, Lifestyle.Singleton);
//Pipeline
container.Collection.Register(typeof(IPipelineBehavior<,>), new[]
{
typeof(RequestExceptionProcessorBehavior<,>),
typeof(RequestExceptionActionProcessorBehavior<,>),
typeof(RequestPreProcessorBehavior<,>),
typeof(RequestPostProcessorBehavior<,>),
typeof(GenericPipelineBehavior<,>)
});
container.Collection.Register(typeof(IRequestPreProcessor<>), new[] { typeof(GenericRequestPreProcessor<>) });
container.Collection.Register(typeof(IRequestPostProcessor<,>), new[] { typeof(GenericRequestPostProcessor<,>), typeof(ConstrainedRequestPostProcessor<,>) });
container.Collection.Register(typeof(IStreamPipelineBehavior<,>), new[]
{
typeof(GenericStreamPipelineBehavior<,>)
});
var serviceProvider = services.BuildServiceProvider().UseSimpleInjector(container);
container.RegisterInstance<IServiceProvider>(container);
var mediator = container.GetRequiredService<IMediator>();
return mediator;
}
private static void RegisterHandlers(Container container, Type collectionType, Assembly[] assemblies)
{
// we have to do this because by default, generic type definitions (such as the Constrained Notification Handler) won't be registered
var handlerTypes = container.GetTypesToRegister(collectionType, assemblies, new TypesToRegisterOptions
{
IncludeGenericTypeDefinitions = true,
IncludeComposites = false,
});
container.Collection.Register(collectionType, handlerTypes);
}
private static IEnumerable<Assembly> GetAssemblies()
{
yield return typeof(IMediator).GetTypeInfo().Assembly;
yield return typeof(Ping).GetTypeInfo().Assembly;
}
}
================================================
FILE: samples/MediatR.Examples.Stashbox/MediatR.Examples.Stashbox.csproj
================================================
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Stashbox" Version="5.17.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MediatR.Examples\MediatR.Examples.csproj" />
</ItemGroup>
</Project>
================================================
FILE: samples/MediatR.Examples.Stashbox/Program.cs
================================================
using Stashbox;
using Stashbox.Configuration;
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
namespace MediatR.Examples.Stashbox;
class Program
{
static Task Main()
{
var writer = new WrappingWriter(Console.Out);
var mediator = BuildMediator(writer);
return Runner.Run(mediator, writer, "Stashbox", testStreams: true);
}
private static IMediator BuildMediator(WrappingWriter writer)
{
var container = new StashboxContainer()
.RegisterInstance<TextWriter>(writer)
.RegisterAssemblies(new[] { typeof(Mediator).Assembly, typeof(Ping).Assembly },
serviceTypeSelector: Rules.ServiceRegistrationFilters.Interfaces, registerSelf: false);
return container.GetRequiredService<IMediator>();
}
}
================================================
FILE: samples/MediatR.Examples.Windsor/ContravariantFilter.cs
================================================
namespace MediatR.Examples.Windsor;
using System;
using System.Linq;
using System.Reflection;
using Castle.MicroKernel;
public class ContravariantFilter : IHandlersFilter
{
public bool HasOpinionAbout(Type service)
{
if (!service.IsGenericType)
return false;
var genericType = service.GetGenericTypeDefinition();
var genericArguments = genericType.GetGenericArguments();
return genericArguments.Count() == 1
&& genericArguments.Single().GenericParameterAttributes.HasFlag(GenericParameterAttributes.Contravariant);
}
public IHandler[] SelectHandlers(Type service, IHandler[] handlers)
{
return handlers;
}
}
================================================
FILE: samples/MediatR.Examples.Windsor/MediatR.Examples.Windsor.csproj
================================================
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MediatR.Examples\MediatR.Examples.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Castle.Windsor" Version="5.1.2" />
<PackageReference Include="Castle.Windsor.Extensions.DependencyInjection" Version="5.1.2" />
</ItemGroup>
</Project>
================================================
FILE: samples/MediatR.Examples.Windsor/Program.cs
================================================
using System.Linq;
using System.Threading.Tasks;
using Castle.MicroKernel.Resolvers.SpecializedResolvers;
using MediatR.Pipeline;
namespace MediatR.Examples.Windsor;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Castle.MicroKernel;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
internal class Program
{
private static Task Main(string[] args)
{
var writer = new WrappingWriter(Console.Out);
var mediator = BuildMediator(writer);
return Runner.Run(mediator, writer, "Castle.Windsor", true);
}
private static IMediator BuildMediator(WrappingWriter writer)
{
var container = new WindsorContainer();
container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel));
container.Kernel.AddHandlersFilter(new ContravariantFilter());
// *** The default lifestyle for Windsor is Singleton
// *** If you are using ASP.net, it's better to register your services with 'Per Web Request LifeStyle'.
var fromAssemblyContainingPing = Classes.FromAssemblyContaining<Ping>();
container.Register(fromAssemblyContainingPing.BasedOn(typeof(IRequestHandler<,>)).WithServiceAllInterfaces().AllowMultipleMatches());
container.Register(fromAssemblyContainingPing.BasedOn(typeof(INotificationHandler<>)).WithServiceAllInterfaces().AllowMultipleMatches());
container.Register(Component.For(typeof(IPipelineBehavior<,>)).ImplementedBy(typeof(RequestExceptionProcessorBehavior<,>)));
container.Register(Component.For(typeof(IPipelineBehavior<,>)).ImplementedBy(typeof(RequestExceptionActionProcessorBehavior<,>)));
container.Register(fromAssemblyContainingPing.BasedOn(typeof(IRequestExceptionAction<,>)).WithServiceAllInterfaces().AllowMultipleMatches());
container.Register(fromAssemblyContainingPing.BasedOn(typeof(IRequestExceptionHandler<,,>)).WithServiceAllInterfaces().AllowMultipleMatches());
container.Register(fromAssemblyContainingPing.BasedOn(typeof(IStreamRequestHandler<,>)).WithServiceAllInterfaces().AllowMultipleMatches());
container.Register(fromAssemblyContainingPing.BasedOn(typeof(IRequestPreProcessor<>)).WithServiceAllInterfaces().AllowMultipleMatches());
container.Register(fromAssemblyContainingPing.BasedOn(typeof(IRequestPostProcessor<,>)).WithServiceAllInterfaces().AllowMultipleMatches());
container.Register(Component.For<IMediator>().ImplementedBy<Mediator>());
container.Register(Component.For<TextWriter>().Instance(writer));
//container.Register(Component.For<ServiceFactory>().UsingFactoryMethod<ServiceFactory>(k => (type =>
//{
// var enumerableType = type
// .GetInterfaces()
// .Concat(new[] { type })
// .FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable<>));
// var service = enumerableType?.GetGenericArguments()?[0];
// var resolvedType = enumerableType != null ? k.ResolveAll(service) : k.Resolve(type);
// var genericArguments = service?.GetGenericArguments();
// // Handle exceptions even using the base request types for IRequestExceptionHandler<,,>
// var isRequestExceptionHandler = service?.GetGenericTypeDefinition()
// ?.IsAssignableTo(typeof(IRequestExceptionHandler<,,>)) ?? false;
// if (isRequestExceptionHandler)
// return ResolveRequestExceptionHandler(k, type, service, resolvedType, genericArguments);
// // Handle exceptions even using the base request types for IRequestExceptionAction<,>
// var isRequestExceptionAction = service?.GetGenericTypeDefinition()
// ?.IsAssignableTo(typeof(IRequestExceptionAction<,>)) ?? false;
// if (isRequestExceptionAction)
// return ResolveRequestExceptionAction(k, type, service, resolvedType, genericArguments);
// return resolvedType;
//})));
//Pipeline
container.Register(Component.For(typeof(IStreamPipelineBehavior<,>)).ImplementedBy(typeof(GenericStreamPipelineBehavior<,>)));
container.Register(Component.For(typeof(IPipelineBehavior<,>)).ImplementedBy(typeof(RequestPreProcessorBehavior<,>)).NamedAutomatically("PreProcessorBehavior"));
container.Register(Component.For(typeof(IPipelineBehavior<,>)).ImplementedBy(typeof(RequestPostProcessorBehavior<,>)).NamedAutomatically("PostProcessorBehavior"));
container.Register(Component.For(typeof(IPipelineBehavior<,>)).ImplementedBy(typeof(GenericPipelineBehavior<,>)).NamedAutomatically("Pipeline"));
container.Register(Component.For(typeof(IRequestPreProcessor<>)).ImplementedBy(typeof(GenericRequestPreProcessor<>)).NamedAutomatically("PreProcessor"));
container.Register(Component.For(typeof(IRequestPostProcessor<,>)).ImplementedBy(typeof(GenericRequestPostProcessor<,>)).NamedAutomatically("PostProcessor"));
container.Register(Component.For(typeof(IRequestPostProcessor<,>), typeof(ConstrainedRequestPostProcessor<,>)).NamedAutomatically("ConstrainedRequestPostProcessor"));
container.Register(Component.For(typeof(INotificationHandler<>), typeof(ConstrainedPingedHandler<>)).NamedAutomatically("ConstrainedPingedHandler"));
var mediator = container.Resolve<IMediator>();
return mediator;
}
private static object ResolveRequestExceptionHandler(IKernel k, Type type, Type service, object resolvedType, Type[] genericArguments)
{
if (service == null
|| genericArguments == null
|| !service.IsInterface
|| !service.IsGenericType
|| !service.IsConstructedGenericType
|| !(service.GetGenericTypeDefinition()
?.IsAssignableTo(typeof(IRequestExceptionHandler<,,>)) ?? false)
|| genericArguments.Length != 3)
{
return resolvedType;
}
var serviceFactory = k.Resolve<ServiceFactory>();
var baseRequestType = genericArguments[0].BaseType;
var response = genericArguments[1];
var exceptionType = genericArguments[2];
// Check if the base request type is valid
if (baseRequestType == null
|| !baseRequestType.IsClass
|| baseRequestType == typeof(object)
|| ((!baseRequestType.GetInterfaces()
?.Any(i => i.IsAssignableFrom(typeof(IRequest<>)))) ?? true))
{
return resolvedType;
}
var exceptionHandlerInterfaceType = typeof(IRequestExceptionHandler<,,>).MakeGenericType(baseRequestType, response, exceptionType);
var enumerableExceptionHandlerInterfaceType = typeof(IEnumerable<>).MakeGenericType(exceptionHandlerInterfaceType);
Array resultArray = CreateArraysOutOfResolvedTypeAndEnumerableInterfaceTypes(type, resolvedType, serviceFactory, enumerableExceptionHandlerInterfaceType);
return resultArray;
}
private static object ResolveRequestExceptionAction(IKernel k, Type type, Type service, object resolvedType, Type[] genericArguments)
{
if (service == null
|| genericArguments == null
|| !service.IsInterface
|| !service.IsGenericType
|| !service.IsConstructedGenericType
|| !(service.GetGenericTypeDefinition()
?.IsAssignableTo(typeof(IRequestExceptionAction<,>)) ?? false)
|| genericArguments.Length != 2)
{
return resolvedType;
}
var serviceFactory = k.Resolve<ServiceFactory>();
var baseRequestType = genericArguments[0].BaseType;
var exceptionType = genericArguments[1];
// Check if the base request type is valid
if (baseRequestType == null
|| !baseRequestType.IsClass
|| baseRequestType == typeof(object)
|| ((!baseRequestType.GetInterfaces()
?.Any(i => i.IsAssignableFrom(typeof(IRequest<>)))) ?? true))
{
return resolvedType;
}
var exceptionHandlerInterfaceType = typeof(IRequestExceptionAction<,>).MakeGenericType(baseRequestType, exceptionType);
var enumerableExceptionHandlerInterfaceType = typeof(IEnumerable<>).MakeGenericType(exceptionHandlerInterfaceType);
Array resultArray = CreateArraysOutOfResolvedTypeAndEnumerableInterfaceTypes(type, resolvedType, serviceFactory, enumerableExceptionHandlerInterfaceType);
return resultArray;
}
private static Array CreateArraysOutOfResolvedTypeAndEnumerableInterfaceTypes(Type type, object resolvedType, ServiceFactory serviceFactory, Type enumerableExceptionHandlerInterfaceType)
{
var firstArray = serviceFactory.Invoke(enumerableExceptionHandlerInterfaceType) as Array;
Debug.Assert(firstArray != null, $"Array '{nameof(firstArray)}' should not be null because this method calls ResolveAll when a {typeof(IEnumerable<>).FullName} " +
$"is passed as argument in argument named '{nameof(type)}'");
var secondArray = resolvedType is Array ? resolvedType as Array : new[] { resolvedType };
Debug.Assert(secondArray != null, $"Array '{nameof(secondArray)}' should not be null because '{nameof(resolvedType)}' is an array or created as an array");
var resultArray = Array.CreateInstance(typeof(object), firstArray.Length + secondArray.Length);
Array.Copy(firstArray, resultArray, firstArray.Length);
Array.Copy(secondArray, 0, resultArray, firstArray.Length, secondArray.Length);
return resultArray;
}
}
================================================
FILE: src/MediatR/Entities/OpenBehavior.cs
================================================
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;
namespace MediatR.Entities;
/// <summary>
/// Represents a registration entity for pipeline behaviors with a specified service lifetime.
/// </summary>
public class OpenBehavior
{
/// <summary>
/// Initializes a new instance of the <see cref="OpenBehavior"/> class.
/// </summary>
/// <param name="openBehaviorType">The type of the pipeline behavior to register.</param>
/// <param name="serviceLifetime">The lifetime of the registered service. Defaults to Transient.</param>
/// <exception cref="InvalidOperationException">Thrown if the specified type does not implement IPipelineBehavior.</exception>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="openBehaviorType"/> is null.</exception>
public OpenBehavior(Type openBehaviorType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
ValidatePipelineBehaviorType(openBehaviorType);
OpenBehaviorType = openBehaviorType;
ServiceLifetime = serviceLifetime;
}
/// <summary>
/// The type of the open behavior.
/// </summary>
public Type OpenBehaviorType { get; }
/// <summary>
/// The service lifetime of the open behavior.
/// </summary>
public ServiceLifetime ServiceLifetime { get; }
/// <summary>
/// Validates whether the specified type implements the <see cref="IPipelineBehavior{TRequest, TResponse}"/> interface.
/// </summary>
/// <param name="openBehaviorType">The type to validate.</param>
/// <exception cref="InvalidOperationException">Thrown if the type does not implement <see cref="IPipelineBehavior{TRequest, TResponse}"/>.</exception>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="openBehaviorType"/> is null.</exception>
private static void ValidatePipelineBehaviorType(Type openBehaviorType)
{
if (openBehaviorType == null) throw new ArgumentNullException($"Open behavior type can not be null.");
bool isPipelineBehavior = openBehaviorType.GetInterfaces()
.Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPipelineBehavior<,>));
if (!isPipelineBehavior)
{
throw new InvalidOperationException($"The type \"{openBehaviorType.Name}\" must implement IPipelineBehavior<,> interface.");
}
}
}
================================================
FILE: src/MediatR/IMediator.cs
================================================
namespace MediatR;
/// <summary>
/// Defines a mediator to encapsulate request/response and publishing interaction patterns
/// </summary>
public interface IMediator : ISender, IPublisher
{
}
================================================
FILE: src/MediatR/INotificationHandler.cs
================================================
using System.Threading;
using System.Threading.Tasks;
namespace MediatR;
/// <summary>
/// Defines a handler for a notification
/// </summary>
/// <typeparam name="TNotification">The type of notification being handled</typeparam>
public interface INotificationHandler<in TNotification>
where TNotification : INotification
{
/// <summary>
/// Handles a notification
/// </summary>
/// <param name="notification">The notification</param>
/// <param name="cancellationToken">Cancellation token</param>
Task Handle(TNotification notification, CancellationToken cancellationToken);
}
/// <summary>
/// Wrapper class for a synchronous notification handler
/// </summary>
/// <typeparam name="TNotification">The notification type</typeparam>
public abstract class NotificationHandler<TNotification> : INotificationHandler<TNotification>
where TNotification : INotification
{
Task INotificationHandler<TNotification>.Handle(TNotification notification, CancellationToken cancellationToken)
{
Handle(notification);
return Task.CompletedTask;
}
/// <summary>
/// Override in a derived class for the handler logic
/// </summary>
/// <param name="notification">Notification</param>
protected abstract void Handle(TNotification notification);
}
================================================
FILE: src/MediatR/INotificationPublisher.cs
================================================
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading;
namespace MediatR;
public interface INotificationPublisher
{
Task Publish(IEnumerable<NotificationHandlerExecutor> handlerExecutors, INotification notification,
CancellationToken cancellationToken);
}
================================================
FILE: src/MediatR/IPipelineBehavior.cs
================================================
namespace MediatR;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Represents an async continuation for the next task to execute in the pipeline
/// </summary>
/// <typeparam name="TResponse">Response type</typeparam>
/// <returns>Awaitable task returning a <typeparamref name="TResponse"/></returns>
public delegate Task<TResponse> RequestHandlerDelegate<TResponse>(CancellationToken t = default);
/// <summary>
/// Pipeline behavior to surround the inner handler.
/// Implementations add additional behavior and await the next delegate.
/// </summary>
/// <typeparam name="TRequest">Request type</typeparam>
/// <typeparam name="TResponse">Response type</typeparam>
public interface IPipelineBehavior<in TRequest, TResponse> where TRequest : notnull
{
/// <summary>
/// Pipeline handler. Perform any additional behavior and await the <paramref name="next"/> delegate as necessary
/// </summary>
/// <param name="request">Incoming request</param>
/// <param name="next">Awaitable delegate for the next action in the pipeline. Eventually this delegate represents the handler.</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Awaitable task returning the <typeparamref name="TResponse"/></returns>
Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken);
}
================================================
FILE: src/MediatR/IPublisher.cs
================================================
using System.Threading;
using System.Threading.Tasks;
namespace MediatR;
/// <summary>
/// Publish a notification or event through the mediator pipeline to be handled by multiple handlers.
/// </summary>
public interface IPublisher
{
/// <summary>
/// Asynchronously send a notification to multiple handlers
/// </summary>
/// <param name="notification">Notification object</param>
/// <param name="cancellationToken">Optional cancellation token</param>
/// <returns>A task that represents the publish operation.</returns>
Task Publish(object notification, CancellationToken cancellationToken = default);
/// <summary>
/// Asynchronously send a notification to multiple handlers
/// </summary>
/// <param name="notification">Notification object</param>
/// <param name="cancellationToken">Optional cancellation token</param>
/// <returns>A task that represents the publish operation.</returns>
Task Publish<TNotification>(TNotification notification, CancellationToken cancellationToken = default)
where TNotification : INotification;
}
================================================
FILE: src/MediatR/IRequestHandler.cs
================================================
using System.Threading;
using System.Threading.Tasks;
namespace MediatR;
/// <summary>
/// Defines a handler for a request
/// </summary>
/// <typeparam name="TRequest">The type of request being handled</typeparam>
/// <typeparam name="TResponse">The type of response from the handler</typeparam>
public interface IRequestHandler<in TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
/// <summary>
/// Handles a request
/// </summary>
/// <param name="request">The request</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Response from the request</returns>
Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken);
}
/// <summary>
/// Defines a handler for a request with a void response.
/// </summary>
/// <typeparam name="TRequest">The type of request being handled</typeparam>
public interface IRequestHandler<in TRequest>
where TRequest : IRequest
{
/// <summary>
/// Handles a request
/// </summary>
/// <param name="request">The request</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Response from the request</returns>
Task Handle(TRequest request, CancellationToken cancellationToken);
}
================================================
FILE: src/MediatR/ISender.cs
================================================
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR;
/// <summary>
/// Send a request through the mediator pipeline to be handled by a single handler.
/// </summary>
public interface ISender
{
/// <summary>
/// Asynchronously send a request to a single handler
/// </summary>
/// <typeparam name="TResponse">Response type</typeparam>
/// <param name="request">Request object</param>
/// <param name="cancellationToken">Optional cancellation token</param>
/// <returns>A task that represents the send operation. The task result contains the handler response</returns>
Task<TResponse> Send<TResponse>(IRequest<TResponse> request, CancellationToken cancellationToken = default);
/// <summary>
/// Asynchronously send a request to a single handler with no response
/// </summary>
/// <param name="request">Request object</param>
/// <param name="cancellationToken">Optional cancellation token</param>
/// <returns>A task that represents the send operation.</returns>
Task Send<TRequest>(TRequest request, CancellationToken cancellationToken = default)
where TRequest : IRequest;
/// <summary>
/// Asynchronously send an object request to a single handler via dynamic dispatch
/// </summary>
/// <param name="request">Request object</param>
/// <param name="cancellationToken">Optional cancellation token</param>
/// <returns>A task that represents the send operation. The task result contains the type erased handler response</returns>
Task<object?> Send(object request, CancellationToken cancellationToken = default);
/// <summary>
/// Create a stream via a single stream handler
/// </summary>
/// <typeparam name="TResponse"></typeparam>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
IAsyncEnumerable<TResponse> CreateStream<TResponse>(IStreamRequest<TResponse> request, CancellationToken cancellationToken = default);
/// <summary>
/// Create a stream via an object request to a stream handler
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
IAsyncEnumerable<object?> CreateStream(object request, CancellationToken cancellationToken = default);
}
================================================
FILE: src/MediatR/IStreamPipelineBehavior.cs
================================================
namespace MediatR;
using System.Collections.Generic;
using System.Threading;
/// <summary>
/// Represents an async enumerable continuation for the next task to execute in the pipeline
/// </summary>
/// <typeparam name="TResponse">Response type</typeparam>
/// <returns>Async Enumerable returning a <typeparamref name="TResponse"/></returns>
public delegate IAsyncEnumerable<TResponse> StreamHandlerDelegate<out TResponse>();
/// <summary>
/// Stream Pipeline behavior to surround the inner handler.
/// Implementations add additional behavior and await the next delegate.
/// </summary>
/// <typeparam name="TRequest">Request type</typeparam>
/// <typeparam name="TResponse">Response type</typeparam>
public interface IStreamPipelineBehavior<in TRequest, TResponse> where TRequest : notnull
{
/// <summary>
/// Stream Pipeline handler. Perform any additional behavior and iterate the <paramref name="next"/> delegate as necessary
/// </summary>
/// <param name="request">Incoming request</param>
/// <param name="next">Awaitable delegate for the next action in the pipeline. Eventually this delegate represents the handler.</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Awaitable task returning the <typeparamref name="TResponse"/></returns>
IAsyncEnumerable<TResponse> Handle(TRequest request, StreamHandlerDelegate<TResponse> next, CancellationToken cancellationToken);
}
================================================
FILE: src/MediatR/IStreamRequestHandler.cs
================================================
using System.Collections.Generic;
using System.Threading;
namespace MediatR;
/// <summary>
/// Defines a handler for a stream request using IAsyncEnumerable as return type.
/// </summary>
/// <typeparam name="TRequest">The type of request being handled</typeparam>
/// <typeparam name="TResponse">The type of response from the handler</typeparam>
public interface IStreamRequestHandler<in TRequest, out TResponse>
where TRequest : IStreamRequest<TResponse>
{
/// <summary>
/// Handles a stream request with IAsyncEnumerable as return type.
/// </summary>
/// <param name="request">The request</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Response from the request</returns>
IAsyncEnumerable<TResponse> Handle(TRequest request, CancellationToken cancellationToken);
}
================================================
FILE: src/MediatR/Internal/HandlersOrderer.cs
================================================
namespace MediatR.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
internal static class HandlersOrderer
{
public static IList<object> Prioritize<TRequest>(IList<object> handlers, TRequest request)
where TRequest : notnull
{
if (handlers.Count < 2)
{
return handlers;
}
var requestObjectDetails = new ObjectDetails(request);
var handlerObjectsDetails = handlers.Select(static s => new ObjectDetails(s)).ToList();
var uniqueHandlers = RemoveOverridden(handlerObjectsDetails).ToArray();
Array.Sort(uniqueHandlers, requestObjectDetails);
return uniqueHandlers.Select(static s => s.Value).ToList();
}
private static IEnumerable<ObjectDetails> RemoveOverridden(IList<ObjectDetails> handlersData)
{
for (var i = 0; i < handlersData.Count - 1; i++)
{
for (var j = i + 1; j < handlersData.Count; j++)
{
if (handlersData[i].IsOverridden || handlersData[j].IsOverridden)
{
continue;
}
if (handlersData[i].Type.IsAssignableFrom(handlersData[j].Type))
{
handlersData[i].IsOverridden = true;
}
else if (handlersData[j].Type.IsAssignableFrom(handlersData[i].Type))
{
handlersData[j].IsOverridden = true;
}
}
}
return handlersData.Where(static w => !w.IsOverridden);
}
}
================================================
FILE: src/MediatR/Internal/ObjectDetails.cs
================================================
using System;
using System.Collections.Generic;
namespace MediatR.Internal;
internal class ObjectDetails : IComparer<ObjectDetails>
{
public string Name { get; }
public string? AssemblyName { get; }
public string? Location { get; }
public object Value { get; }
public Type Type { get; }
public bool IsOverridden { get; set; }
public ObjectDetails(object value)
{
Value = value;
Type = Value.GetType();
var exceptionHandlerType = value.GetType();
Name = exceptionHandlerType.Name;
AssemblyName = exceptionHandlerType.Assembly.GetName().Name;
Location = exceptionHandlerType.Namespace?.Replace($"{AssemblyName}.", string.Empty);
}
public int Compare(ObjectDetails? x, ObjectDetails? y)
{
if (x == null)
{
return 1;
}
if (y == null)
{
return -1;
}
return CompareByAssembly(x, y) ?? CompareByNamespace(x, y) ?? CompareByLocation(x, y);
}
/// <summary>
/// Compare two objects according to current assembly
/// </summary>
/// <param name="x">First object to compare</param>
/// <param name="y">Second object to compare</param>
/// <returns>
/// An object has a higher priority if it belongs to the current assembly and the other is not;
/// If none of the objects belong to the current assembly, they can be considered equal;
/// If both objects belong to the current assembly, they can't be compared only by this criterion.
/// </returns>
private int? CompareByAssembly(ObjectDetails x, ObjectDetails y)
{
if (x.AssemblyName == AssemblyName && y.AssemblyName != AssemblyName)
{
return -1;
}
if (x.AssemblyName != AssemblyName && y.AssemblyName == AssemblyName)
{
return 1;
}
if (x.AssemblyName != AssemblyName && y.AssemblyName != AssemblyName)
{
return 0;
}
return null;
}
/// <summary>
/// Compare two objects according to current namespace
/// </summary>
/// <param name="x">First object to compare</param>
/// <param name="y">Second object to compare</param>
/// <returns>
/// An object has a higher priority if it belongs to the current/child namespace and the other is not;
/// If both objects belong to the current/child namespace, they can be considered equal;
/// If none of the objects belong to the current/child namespace, they can't be compared by this criterion.
/// </returns>
private int? CompareByNamespace(ObjectDetails x, ObjectDetails y)
{
if (Location is null || x.Location is null || y.Location is null)
{
return 0;
}
if (x.Location.StartsWith(Location, StringComparison.Ordinal) && !y.Location.StartsWith(Location, StringComparison.Ordinal))
{
return -1;
}
if (!x.Location.StartsWith(Location, StringComparison.Ordinal) && y.Location.StartsWith(Location, StringComparison.Ordinal))
{
return 1;
}
if (x.Location.StartsWith(Location, StringComparison.Ordinal) && y.Location.StartsWith(Location, StringComparison.Ordinal))
{
return 0;
}
return null;
}
/// <summary>
/// Compare two objects according to location in the assembly
/// </summary>
/// <param name="x">First object to compare</param>
/// <param name="y">Second object to compare</param>
/// <returns>
/// An object has a higher priority if it location is part of the current location and the other is not;
/// If both objects are part of the current location, the closest has higher priority;
/// If none of the objects are part of the current location, they can be considered equal.
/// </returns>
private int CompareByLocation(ObjectDetails x, ObjectDetails y)
{
if (Location is null || x.Location is null || y.Location is null)
{
return 0;
}
if (Location.StartsWith(x.Location, StringComparison.Ordinal) && !Location.StartsWith(y.Location, StringComparison.Ordinal))
{
return -1;
}
if (!Location.StartsWith(x.Location, StringComparison.Ordinal) && Location.StartsWith(y.Location, StringComparison.Ordinal))
{
return 1;
}
if (x.Location.Length > y.Location.Length)
{
return -1;
}
if (x.Location.Length < y.Location.Length)
{
return 1;
}
return 0;
}
}
================================================
FILE: src/MediatR/Licensing/BuildInfo.cs
================================================
using System;
using System.Linq;
using System.Reflection;
namespace MediatR.Licensing;
internal static class BuildInfo
{
public static DateTimeOffset? BuildDate { get; } = GetBuildDate();
private static DateTimeOffset? GetBuildDate()
{
var assembly = typeof(BuildInfo).Assembly;
var buildDateAttribute = assembly
.GetCustomAttributes<AssemblyMetadataAttribute>()
.FirstOrDefault(a => a.Key == "BuildDateUtc");
if (buildDateAttribute?.Value != null &&
DateTimeOffset.TryParse(buildDateAttribute.Value, out var buildDate))
{
return buildDate;
}
return null;
}
}
================================================
FILE: src/MediatR/Licensing/Edition.cs
================================================
namespace MediatR.Licensing;
internal enum Edition
{
Community = 0,
Standard = 1,
Professional = 2,
Enterprise = 3
}
================================================
FILE: src/MediatR/Licensing/License.cs
================================================
using System;
using System.Diagnostics.CodeAnalysis;
using System.Security.Claims;
namespace MediatR.Licensing;
internal class License
{
internal License(params Claim[] claims) : this(new ClaimsPrincipal(new ClaimsIdentity(claims)))
{
}
public License(ClaimsPrincipal claims)
{
if (Guid.TryParse(claims.FindFirst("account_id")?.Value, out var accountId))
{
AccountId = accountId;
}
CustomerId = claims.FindFirst("customer_id")?.Value;
SubscriptionId = claims.FindFirst("sub_id")?.Value;
if (long.TryParse(claims.FindFirst("iat")?.Value, out var iat))
{
var startedAt = DateTimeOffset.FromUnixTimeSeconds(iat);
StartDate = startedAt;
}
if (long.TryParse(claims.FindFirst("exp")?.Value, out var exp))
{
var expiredAt = DateTimeOffset.FromUnixTimeSeconds(exp);
ExpirationDate = expiredAt;
}
if (Enum.TryParse<Edition>(claims.FindFirst("edition")?.Value, out var edition))
{
Edition = edition;
}
if (Enum.TryParse<ProductType>(claims.FindFirst("type")?.Value, out var productType))
{
ProductType = productType;
}
var perpetualValue = claims.FindFirst("perpetual")?.Value;
IsPerpetual = perpetualValue?.ToLowerInvariant() is "true" or "1";
IsConfigured = AccountId != null
&& CustomerId != null
&& SubscriptionId != null
&& StartDate != null
&& ExpirationDate != null
&& Edition != null
&& ProductType != null;
}
public Guid? AccountId { get; }
public string? CustomerId { get; }
public string? SubscriptionId { get; }
public DateTimeOffset? StartDate { get; }
public DateTimeOffset? ExpirationDate { get; }
public Edition? Edition { get; }
public ProductType? ProductType { get; }
public bool IsPerpetual { get; }
public bool IsConfigured { get; }
}
================================================
FILE: src/MediatR/Licensing/LicenseAccessor.cs
================================================
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Security.Claims;
using System.Security.Cryptography;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.JsonWebTokens;
using Microsoft.IdentityModel.Tokens;
using Convert = System.Convert;
namespace MediatR.Licensing;
internal class LicenseAccessor
{
private readonly MediatRServiceConfiguration? _configuration;
private readonly ILogger _logger;
public LicenseAccessor(MediatRServiceConfiguration configuration, ILoggerFactory loggerFactory)
{
_configuration = configuration;
_logger = loggerFactory.CreateLogger("LuckyPennySoftware.MediatR.License");
}
public LicenseAccessor(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger("LuckyPennySoftware.MediatR.License");
}
private License? _license;
private readonly object _lock = new();
public License Current => _license ??= Initialize();
private License Initialize()
{
lock (_lock)
{
if (_license != null)
{
return _license;
}
var key = _configuration?.LicenseKey
?? Mediator.LicenseKey
?? null;
if (key == null)
{
return new License();
}
var licenseClaims = ValidateKey(key);
return licenseClaims.Any()
? new License(new ClaimsPrincipal(new ClaimsIdentity(licenseClaims)))
: new License();
}
}
private Claim[] ValidateKey(string licenseKey)
{
var handler = new JsonWebTokenHandler();
var rsa = new RSAParameters
{
Exponent = Convert.FromBase64String("AQAB"),
Modulus = Convert.FromBase64String(
"2LTtdJV2b0mYoRqChRCfcqnbpKvsiCcDYwJ+qPtvQXWXozOhGo02/V0SWMFBdbZHUzpEytIiEcojo7Vbq5mQmt4lg92auyPKsWq6qSmCVZCUuL/kpYqLCit4yUC0YqZfw4H9zLf1yAIOgyXQf1x6g+kscDo1pWAniSl9a9l/LXRVEnGz+OfeUrN/5gzpracGUY6phx6T09UCRuzi4YqqO4VJzL877W0jCW2Q7jMzHxOK04VSjNc22CADuCd34mrFs23R0vVm1DVLYtPGD76/rGOcxO6vmRc7ydBAvt1IoUsrY0vQ2rahp51YPxqqhKPd8nNOomHWblCCA7YUeV3C1Q==")
};;
var key = new RsaSecurityKey(rsa)
{
KeyId = "LuckyPennySoftwareLicenseKey/bbb13acb59904d89b4cb1c85f088ccf9"
};
var parms = new TokenValidationParameters
{
ValidIssuer = "https://luckypennysoftware.com",
ValidAudience = "LuckyPennySoftware",
IssuerSigningKey = key,
ValidateLifetime = false
};
var validateResult = Task.Run(() => handler.ValidateTokenAsync(licenseKey, parms)).GetAwaiter().GetResult();
if (!validateResult.IsValid)
{
_logger.LogCritical(validateResult.Exception, "Error validating the Lucky Penny software license key");
}
return validateResult.ClaimsIdentity?.Claims.ToArray() ?? Array.Empty<Claim>();
}
}
================================================
FILE: src/MediatR/Licensing/LicenseValidator.cs
================================================
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
namespace MediatR.Licensing;
internal class LicenseValidator
{
private readonly ILogger _logger;
private readonly DateTimeOffset? _buildDate;
public LicenseValidator(ILoggerFactory loggerFactory) : this(loggerFactory, BuildInfo.BuildDate)
{
}
public LicenseValidator(ILoggerFactory loggerFactory, DateTimeOffset? buildDate)
{
_logger = loggerFactory.CreateLogger("LuckyPennySoftware.MediatR.License");
_buildDate = buildDate;
}
public void Validate(License license)
{
var errors = new List<string>();
if (license is not { IsConfigured: true })
{
var message = "You do not have a valid license key for the Lucky Penny software MediatR. " +
"This is allowed for development and testing scenarios. " +
"If you are running in production you are required to have a licensed version. " +
"Please visit https://luckypennysoftware.com to obtain a valid license.";
_logger.LogWarning(message);
return;
}
_logger.LogDebug("The Lucky Penny license key details: {license}", license);
var diff = DateTime.UtcNow.Date.Subtract(license.ExpirationDate!.Value.Date).TotalDays;
if (diff > 0)
{
// If perpetual, check if build date is before expiration
if (license.IsPerpetual && _buildDate.HasValue)
{
var buildDateDiff = _buildDate.Value.Date.Subtract(license.ExpirationDate.Value.Date).TotalDays;
if (buildDateDiff <= 0)
{
_logger.LogInformation(
"Your license for the Lucky Penny software MediatR expired {expiredDaysAgo} days ago, but perpetual licensing is active because the build date ({buildDate:O}) is before the license expiration date ({licenseExpiration:O}).",
diff, _buildDate, license.ExpirationDate);
// Don't add to errors - perpetual fallback applies
}
else
{
errors.Add($"Your license for the Lucky Penny software MediatR expired {diff} days ago.");
}
}
else
{
if (license.IsPerpetual)
{
_logger.LogWarning(
"Your license for the Lucky Penny software MediatR has perpetual licensing enabled, but the build date could not be determined. Perpetual licensing cannot be applied. Please ensure the assembly metadata is correctly embedded at build time.");
}
errors.Add($"Your license for the Lucky Penny software MediatR expired {diff} days ago.");
}
}
if (license.ProductType!.Value != ProductType.MediatR
&& license.ProductType.Value != ProductType.Bundle)
{
errors.Add("Your Lucky Penny software license does not include MediatR.");
}
if (errors.Count > 0)
{
foreach (var err in errors)
{
_logger.LogError(err);
}
_logger.LogError(
"Please visit https://luckypennysoftware.com to obtain a valid license for the Lucky Penny software MediatR.");
}
else
{
_logger.LogInformation("You have a valid license key for the Lucky Penny software {type} {edition} edition. The license expires on {licenseExpiration}.",
license.ProductType,
license.Edition,
license.ExpirationDate);
}
}
}
================================================
FILE: src/MediatR/Licensing/ProductType.cs
================================================
namespace MediatR.Licensing;
internal enum ProductType
{
AutoMapper = 0,
MediatR = 1,
Bundle = 2
}
================================================
FILE: src/MediatR/MediatR.csproj
================================================
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Authors>Jimmy Bogard</Authors>
<Description>Simple, unambitious mediator implementation in .NET</Description>
<Copyright>Copyright Jimmy Bogard</Copyright>
<TargetFrameworks>netstandard2.0;net8.0;net9.0;net10.0</TargetFrameworks>
<Nullable>enable</Nullable>
<Features>strict</Features>
<PackageTags>mediator;request;response;queries;commands;notifications</PackageTags>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\MediatR.snk</AssemblyOriginatorKeyFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageIcon>gradient_128x128.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<PackageProjectUrl>https://mediatr.io</PackageProjectUrl>
<MinVerTagPrefix>v</MinVerTagPrefix>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Deterministic>true</Deterministic>
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
</PropertyGroup>
<PropertyGroup Condition=" '$(IsWindows)' == 'true' ">
<TargetFrameworks>$(TargetFrameworks);net462</TargetFrameworks>
</PropertyGroup>
<Target Name="EmbedBuildDate" BeforeTargets="CoreCompile">
<Exec Command="git log -1 --format=%25cI" ConsoleToMSBuild="true" IgnoreExitCode="true">
<Output TaskParameter="ConsoleOutput" PropertyName="BuildDateUtc" />
</Exec>
<PropertyGroup>
<BuildDateUtc Condition="'$(BuildDateUtc)' == ''">$([System.DateTime]::UtcNow.ToString("O"))</BuildDateUtc>
</PropertyGroup>
<WriteLinesToFile File="$(IntermediateOutputPath)BuildDateGenerated.cs" Lines="[assembly: System.Reflection.AssemblyMetadata("BuildDateUtc", "$(BuildDateUtc)")]" Overwrite="true" />
<ItemGroup>
<Compile Include="$(IntermediateOutputPath)BuildDateGenerated.cs" />
</ItemGroup>
</Target>
<ItemGroup>
<None Include="..\..\assets\logo\gradient_128x128.png" Pack="true" PackagePath="" />
<None Include="..\..\LICENSE.md" Pack="true" PackagePath="" />
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>MediatR.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010091986edd141861f402457659cb82b56cf6a0d60b3bd2e5aa4ea73d88afa929d278462d6c4c0e2ecbce21948c15514a310a82e6b2e6beaab6cb14230a03bc026609be59f938423f2490fa0033ae87a982fb4950db77d1a4635e14f7727161e93e5511de766ed8e515efd801464b7820a27fca30a32161485824e442cc5ffecfbe</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
<PackageReference Include="IsExternalInit" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MediatR.Contracts" Version="[2.0.1, 3.0.0)" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="[10.0.0, )" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="[10.0.0, )" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="[10.0.0, )" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="[8.14.0, )" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="6.0.0" PrivateAssets="All" />
</ItemGroup>
</Project>
================================================
FILE: src/MediatR/Mediator.cs
================================================
using MediatR.NotificationPublishers;
using Microsoft.Extensions.DependencyInjection;
namespace MediatR;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Wrappers;
/// <summary>
/// Default mediator implementation relying on single- and multi instance delegates for resolving handlers.
/// </summary>
public class Mediator : IMediator
{
private readonly IServiceProvider _serviceProvider;
private readonly INotificationPublisher _publisher;
private static readonly ConcurrentDictionary<Type, RequestHandlerBase> _requestHandlers = new();
private static readonly ConcurrentDictionary<Type, NotificationHandlerWrapper> _notificationHandlers = new();
private static readonly ConcurrentDictionary<Type, StreamRequestHandlerBase> _streamRequestHandlers = new();
/// <summary>
/// Initializes a new instance of the <see cref="Mediator"/> class.
/// </summary>
/// <param name="serviceProvider">Service provider. Can be a scoped or root provider</param>
public Mediator(IServiceProvider serviceProvider)
: this(serviceProvider, new ForeachAwaitPublisher()) { }
/// <summary>
/// Initializes a new instance of the <see cref="Mediator"/> class.
/// </summary>
/// <param name="serviceProvider">Service provider. Can be a scoped or root provider</param>
/// <param name="publisher">Notification publisher. Defaults to <see cref="ForeachAwaitPublisher"/>.</param>
public Mediator(IServiceProvider serviceProvider, INotificationPublisher publisher)
{
_serviceProvider = serviceProvider;
_publisher = publisher;
_serviceProvider.CheckLicense();
}
/// <summary>
/// Gets or sets the license key. You can find your license key in your <a href="https://luckypennysoftware.com/account">account</a>.
/// </summary>
public static string? LicenseKey { get; set; }
public Task<TResponse> Send<TResponse>(IRequest<TResponse> request, CancellationToken cancellationToken = default)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
var handler = (RequestHandlerWrapper<TResponse>)_requestHandlers.GetOrAdd(request.GetType(), static requestType =>
{
var wrapperType = typeof(RequestHandlerWrapperImpl<,>).MakeGenericType(requestType, typeof(TResponse));
var wrapper = Activator.CreateInstance(wrapperType) ?? throw new InvalidOperationException($"Could not create wrapper type for {requestType}");
return (RequestHandlerBase)wrapper;
});
return handler.Handle(request, _serviceProvider, cancellationToken);
}
public Task Send<TRequest>(TRequest request, CancellationToken cancellationToken = default)
where TRequest : IRequest
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
var handler = (RequestHandlerWrapper)_requestHandlers.GetOrAdd(request.GetType(), static requestType =>
{
var wrapperType = typeof(RequestHandlerWrapperImpl<>).MakeGenericType(requestType);
var wrapper = Activator.CreateInstance(wrapperType) ?? throw new InvalidOperationException($"Could not create wrapper type for {requestType}");
return (RequestHandlerBase)wrapper;
});
return handler.Handle(request, _serviceProvider, cancellationToken);
}
public Task<object?> Send(object request, CancellationToken cancellationToken = default)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
var handler = _requestHandlers.GetOrAdd(request.GetType(), static requestType =>
{
Type wrapperType;
var requestInterfaceType = requestType.GetInterfaces().FirstOrDefault(static i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IRequest<>));
if (requestInterfaceType is null)
{
requestInterfaceType = requestType.GetInterfaces().FirstOrDefault(static i => i == typeof(IRequest));
if (requestInterfaceType is null)
{
throw new ArgumentException($"{requestType.Name} does not implement {nameof(IRequest)}", nameof(request));
}
wrapperType = typeof(RequestHandlerWrapperImpl<>).MakeGenericType(requestType);
}
else
{
var responseType = requestInterfaceType.GetGenericArguments()[0];
wrapperType = typeof(RequestHandlerWrapperImpl<,>).MakeGenericType(requestType, responseType);
}
var wrapper = Activator.CreateInstance(wrapperType) ?? throw new InvalidOperationException($"Could not create wrapper for type {requestType}");
return (RequestHandlerBase)wrapper;
});
// call via dynamic dispatch to avoid calling through reflection for performance reasons
return handler.Handle(request, _serviceProvider, cancellationToken);
}
public Task Publish<TNotification>(TNotification notification, CancellationToken cancellationToken = default)
where TNotification : INotification
{
if (notification == null)
{
throw new ArgumentNullException(nameof(notification));
}
return PublishNotification(notification, cancellationToken);
}
public Task Publish(object notification, CancellationToken cancellationToken = default) =>
notification switch
{
null => throw new ArgumentNullException(nameof(notification)),
INotification instance => PublishNotification(instance, cancellationToken),
_ => throw new ArgumentException($"{nameof(notification)} does not implement ${nameof(INotification)}")
};
/// <summary>
/// Override in a derived class to control how the tasks are awaited. By default the implementation calls the <see cref="INotificationPublisher"/>.
/// </summary>
/// <param name="handlerExecutors">Enumerable of tasks representing invoking each notification handler</param>
/// <param name="notification">The notification being published</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <returns>A task representing invoking all handlers</returns>
protected virtual Task PublishCore(IEnumerable<NotificationHandlerExecutor> handlerExecutors, INotification notification, CancellationToken cancellationToken)
=> _publisher.Publish(handlerExecutors, notification, cancellationToken);
private Task PublishNotification(INotification notification, CancellationToken cancellationToken = default)
{
var handler = _notificationHandlers.GetOrAdd(notification.GetType(), static notificationType =>
{
var wrapperType = typeof(NotificationHandlerWrapperImpl<>).MakeGenericType(notificationType);
var wrapper = Activator.CreateInstance(wrapperType) ?? throw new InvalidOperationException($"Could not create wrapper for type {notificationType}");
return (NotificationHandlerWrapper)wrapper;
});
return handler.Handle(notification, _serviceProvider, PublishCore, cancellationToken);
}
public IAsyncEnumerable<TResponse> CreateStream<TResponse>(IStreamRequest<TResponse> request, CancellationToken cancellationToken = default)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
var streamHandler = (StreamRequestHandlerWrapper<TResponse>)_streamRequestHandlers.GetOrAdd(request.GetType(), static requestType =>
{
var wrapperType = typeof(StreamRequestHandlerWrapperImpl<,>).MakeGenericType(requestType, typeof(TResponse));
var wrapper = Activator.CreateInstance(wrapperType) ?? throw new InvalidOperationException($"Could not create wrapper for type {requestType}");
return (StreamRequestHandlerBase)wrapper;
});
var items = streamHandler.Handle(request, _serviceProvider, cancellationToken);
return items;
}
public IAsyncEnumerable<object?> CreateStream(object request, CancellationToken cancellationToken = default)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
var handler = _streamRequestHandlers.GetOrAdd(request.GetType(), static requestType =>
{
var requestInterfaceType = requestType.GetInterfaces().FirstOrDefault(static i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IStreamRequest<>));
if (requestInterfaceType is null)
{
throw new ArgumentException($"{requestType.Name} does not implement IStreamRequest<TResponse>", nameof(request));
}
var responseType = requestInterfaceType.GetGenericArguments()[0];
var wrapperType = typeof(StreamRequestHandlerWrapperImpl<,>).MakeGenericType(requestType, responseType);
var wrapper = Activator.CreateInstance(wrapperType) ?? throw new InvalidOperationException($"Could not create wrapper for type {requestType}");
return (StreamRequestHandlerBase)wrapper;
});
var items = handler.Handle(request, _serviceProvider, cancellationToken);
return items;
}
}
================================================
FILE: src/MediatR/MicrosoftExtensionsDI/MediatRServiceCollectionExtensions.cs
================================================
using System;
using System.Linq;
using MediatR;
using MediatR.Licensing;
using MediatR.Pipeline;
using MediatR.Registration;
using Microsoft.Extensions.Logging;
namespace Microsoft.Extensions.DependencyInjection;
/// <summary>
/// Extensions to scan for MediatR handlers and registers them.
/// - Scans for any handler interface implementations and registers them as <see cref="ServiceLifetime.Transient"/>
/// - Scans for any <see cref="IRequestPreProcessor{TRequest}"/> and <see cref="IRequestPostProcessor{TRequest,TResponse}"/> implementations and registers them as transient instances
/// Registers <see cref="IMediator"/> as a transient instance
/// After calling AddMediatR you can use the container to resolve an <see cref="IMediator"/> instance.
/// This does not scan for any <see cref="IPipelineBehavior{TRequest,TResponse}"/> instances including <see cref="RequestPreProcessorBehavior{TRequest,TResponse}"/> and <see cref="RequestPreProcessorBehavior{TRequest,TResponse}"/>.
/// To register behaviors, use the <see cref="ServiceCollectionServiceExtensions.AddTransient(IServiceCollection,Type,Type)"/> with the open generic or closed generic types.
/// </summary>
public static class MediatRServiceCollectionExtensions
{
/// <summary>
/// Registers handlers and mediator types from the specified assemblies
/// </summary>
/// <param name="services">Service collection</param>
/// <param name="configuration">The action used to configure the options</param>
/// <returns>Service collection</returns>
public static IServiceCollection AddMediatR(this IServiceCollection services,
Action<MediatRServiceConfiguration> configuration)
{
var serviceConfig = new MediatRServiceConfiguration();
configuration.Invoke(serviceConfig);
return services.AddMediatR(serviceConfig);
}
/// <summary>
/// Registers handlers and mediator types from the specified assemblies
/// </summary>
/// <param name="services">Service collection</param>
/// <param name="configuration">Configuration options</param>
/// <returns>Service collection</returns>
public static IServiceCollection AddMediatR(this IServiceCollection services,
MediatRServiceConfiguration configuration)
{
if (!configuration.AssembliesToRegister.Any())
{
throw new ArgumentException("No assemblies found to scan. Supply at least one assembly to scan for handlers.");
}
ServiceRegistrar.SetGenericRequestHandlerRegistrationLimitations(configuration);
ServiceRegistrar.AddMediatRClassesWithTimeout(services, configuration);
ServiceRegistrar.AddRequiredServices(services, configuration);
return services;
}
internal static void CheckLicense(this IServiceProvider serviceProvider)
{
if (LicenseChecked == false)
{
var licenseAccessor = serviceProvider.GetRequiredService<LicenseAccessor>();
var licenseValidator = serviceProvider.GetRequiredService<LicenseValidator>();
var license = licenseAccessor.Current;
licenseValidator.Validate(license);
}
LicenseChecked = true;
}
internal static bool LicenseChecked { get; set; }
}
================================================
FILE: src/MediatR/MicrosoftExtensionsDI/MediatrServiceConfiguration.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using MediatR;
using MediatR.Entities;
using MediatR.NotificationPublishers;
using MediatR.Pipeline;
using MediatR.Registration;
namespace Microsoft.Extensions.DependencyInjection;
public class MediatRServiceConfiguration
{
/// <summary>
/// Optional filter for types to register. Default value is a function returning true.
/// </summary>
public Func<Type, bool> TypeEvaluator { get; set; } = t => true;
/// <summary>
/// Mediator implementation type to register. Default is <see cref="Mediator"/>
/// </summary>
public Type MediatorImplementationType { get; set; } = typeof(Mediator);
/// <summary>
/// Strategy for publishing notifications. Defaults to <see cref="ForeachAwaitPublisher"/>
/// </summary>
public INotificationPublisher NotificationPublisher { get; set; } = new ForeachAwaitPublisher();
/// <summary>
/// Type of notification publisher strategy to register. If set, overrides <see cref="NotificationPublisher"/>
/// </summary>
public Type? NotificationPublisherType { get; set; }
/// <summary>
/// Service lifetime to register services under. Default value is <see cref="ServiceLifetime.Transient"/>
/// </summary>
public ServiceLifetime Lifetime { get; set; } = ServiceLifetime.Transient;
/// <summary>
/// Request exception action processor strategy. Default value is <see cref="DependencyInjection.RequestExceptionActionProcessorStrategy.ApplyForUnhandledExceptions"/>
/// </summary>
public RequestExceptionActionProcessorStrategy RequestExceptionActionProcessorStrategy { get; set; }
= RequestExceptionActionProcessorStrategy.ApplyForUnhandledExceptions;
internal List<Assembly> AssembliesToRegister { get; } = new();
/// <summary>
/// List of behaviors to register in specific order
/// </summary>
public List<ServiceDescriptor> BehaviorsToRegister { get; } = new();
/// <summary>
/// List of stream behaviors to register in specific order
/// </summary>
public List<ServiceDescriptor> StreamBehaviorsToRegister { get; } = new();
/// <summary>
/// List of request pre processors to register in specific order
/// </summary>
public List<ServiceDescriptor> RequestPreProcessorsToRegister { get; } = new();
/// <summary>
/// List of request post processors to register in specific order
/// </summary>
public List<ServiceDescriptor> RequestPostProcessorsToRegister { get; } = new();
/// <summary>
/// Automatically register processors during assembly scanning
/// </summary>
public bool AutoRegisterRequestProcessors { get; set; }
/// <summary>
/// Configure the maximum number of type parameters that a generic request handler can have. To Disable this constraint, set the value to 0.
/// </summary>
public int MaxGenericTypeParameters { get; set; } = 10;
/// <summary>
/// Configure the maximum number of types that can close a generic request type parameter constraint. To Disable this constraint, set the value to 0.
/// </summary>
public int MaxTypesClosing { get; set; } = 100;
/// <summary>
/// Configure the Maximum Amount of Generic RequestHandler Types MediatR will try to register. To Disable this constraint, set the value to 0.
/// </summary>
public int MaxGenericTypeRegistrations { get; set; } = 125000;
/// <summary>
/// Configure the Timeout in Milliseconds that the GenericHandler Registration Process will exit with error. To Disable this constraint, set the value to 0.
/// </summary>
public int RegistrationTimeout { get; set; } = 15000;
/// <summary>
/// Flag that controlls whether MediatR will attempt to register handlers that containg generic type parameters.
/// </summary>
public bool RegisterGenericHandlers { get; set; } = false;
/// <summary>
/// Gets or sets the license key. You can find your license key in your <a href="https://luckypennysoftware.com/account">account</a>.
/// </summary>
public string? LicenseKey { get; set; }
/// <summary>
/// Register various handlers from assembly containing given type
/// </summary>
/// <typeparam name="T">Type from assembly to scan</typeparam>
/// <returns>This</returns>
public MediatRServiceConfiguration RegisterServicesFromAssemblyContaining<T>()
=> RegisterServicesFromAssemblyContaining(typeof(T));
/// <summary>
/// Register various handlers from assembly containing given type
/// </summary>
/// <param name="type">Type from assembly to scan</param>
/// <returns>This</returns>
public MediatRServiceConfiguration RegisterServicesFromAssemblyContaining(Type type)
=> RegisterServicesFromAssembly(type.Assembly);
/// <summary>
/// Register various handlers from assembly
/// </summary>
/// <param name="assembly">Assembly to scan</param>
/// <returns>This</returns>
public MediatRServiceConfiguration RegisterServicesFromAssembly(Assembly assembly)
{
AssembliesToRegister.Add(assembly);
return this;
}
/// <summary>
/// Register various handlers from assemblies
/// </summary>
/// <param name="assemblies">Assemblies to scan</param>
/// <returns>This</returns>
public MediatRServiceConfiguration RegisterServicesFromAssemblies(
params Assembly[] assemblies)
{
AssembliesToRegister.AddRange(assemblies);
return this;
}
/// <summary>
/// Register a closed behavior type
/// </summary>
/// <typeparam name="TServiceType">Closed behavior interface type</typeparam>
/// <typeparam name="TImplementationType">Closed behavior implementation type</typeparam>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddBehavior<TServiceType, TImplementationType>(ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
=> AddBehavior(typeof(TServiceType), typeof(TImplementationType), serviceLifetime);
/// <summary>
/// Register a closed behavior type against all <see cref="IPipelineBehavior{TRequest,TResponse}"/> implementations
/// </summary>
/// <typeparam name="TImplementationType">Closed behavior implementation type</typeparam>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddBehavior<TImplementationType>(ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
return AddBehavior(typeof(TImplementationType), serviceLifetime);
}
/// <summary>
/// Register a closed behavior type against all <see cref="IPipelineBehavior{TRequest,TResponse}"/> implementations
/// </summary>
/// <param name="implementationType">Closed behavior implementation type</param>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddBehavior(Type implementationType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
var implementedGenericInterfaces = implementationType.FindInterfacesThatClose(typeof(IPipelineBehavior<,>)).ToList();
if (implementedGenericInterfaces.Count == 0)
{
throw new InvalidOperationException($"{implementationType.Name} must implement {typeof(IPipelineBehavior<,>).FullName}");
}
foreach (var implementedBehaviorType in implementedGenericInterfaces)
{
BehaviorsToRegister.Add(new ServiceDescriptor(implementedBehaviorType, implementationType, serviceLifetime));
}
return this;
}
/// <summary>
/// Register a closed behavior type
/// </summary>
/// <param name="serviceType">Closed behavior interface type</param>
/// <param name="implementationType">Closed behavior implementation type</param>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddBehavior(Type serviceType, Type implementationType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
BehaviorsToRegister.Add(new ServiceDescriptor(serviceType, implementationType, serviceLifetime));
return this;
}
/// <summary>
/// Registers an open behavior type against the <see cref="IPipelineBehavior{TRequest,TResponse}"/> open generic interface type
/// </summary>
/// <param name="openBehaviorType">An open generic behavior type</param>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddOpenBehavior(Type openBehaviorType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
if (!openBehaviorType.IsGenericType)
{
throw new InvalidOperationException($"{openBehaviorType.Name} must be generic");
}
var implementedGenericInterfaces = openBehaviorType.GetInterfaces().Where(i => i.IsGenericType).Select(i => i.GetGenericTypeDefinition());
var implementedOpenBehaviorInterfaces = new HashSet<Type>(implementedGenericInterfaces.Where(i => i == typeof(IPipelineBehavior<,>)));
if (implementedOpenBehaviorInterfaces.Count == 0)
{
throw new InvalidOperationException($"{openBehaviorType.Name} must implement {typeof(IPipelineBehavior<,>).FullName}");
}
foreach (var openBehaviorInterface in implementedOpenBehaviorInterfaces)
{
BehaviorsToRegister.Add(new ServiceDescriptor(openBehaviorInterface, openBehaviorType, serviceLifetime));
}
return this;
}
/// <summary>
/// Registers multiple open behavior types against the <see cref="IPipelineBehavior{TRequest,TResponse}"/> open generic interface type
/// </summary>
/// <param name="openBehaviorTypes">An open generic behavior type list includes multiple open generic behavior types.</param>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddOpenBehaviors(IEnumerable<Type> openBehaviorTypes, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
foreach (var openBehaviorType in openBehaviorTypes)
{
AddOpenBehavior(openBehaviorType, serviceLifetime);
}
return this;
}
/// <summary>
/// Registers open behaviors against the <see cref="IPipelineBehavior{TRequest,TResponse}"/> open generic interface type
/// </summary>
/// <param name="openBehaviors">An open generic behavior list includes multiple <see cref="OpenBehavior"/> open generic behaviors.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddOpenBehaviors(IEnumerable<OpenBehavior> openBehaviors)
{
foreach (var openBehavior in openBehaviors)
{
AddOpenBehavior(openBehavior.OpenBehaviorType!, openBehavior.ServiceLifetime);
}
return this;
}
/// <summary>
/// Register a closed stream behavior type
/// </summary>
/// <typeparam name="TServiceType">Closed stream behavior interface type</typeparam>
/// <typeparam name="TImplementationType">Closed stream behavior implementation type</typeparam>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddStreamBehavior<TServiceType, TImplementationType>(ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
=> AddStreamBehavior(typeof(TServiceType), typeof(TImplementationType), serviceLifetime);
/// <summary>
/// Register a closed stream behavior type
/// </summary>
/// <param name="serviceType">Closed stream behavior interface type</param>
/// <param name="implementationType">Closed stream behavior implementation type</param>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddStreamBehavior(Type serviceType, Type implementationType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
StreamBehaviorsToRegister.Add(new ServiceDescriptor(serviceType, implementationType, serviceLifetime));
return this;
}
/// <summary>
/// Register a closed stream behavior type against all <see cref="IStreamPipelineBehavior{TRequest,TResponse}"/> implementations
/// </summary>
/// <typeparam name="TImplementationType">Closed stream behavior implementation type</typeparam>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddStreamBehavior<TImplementationType>(ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
=> AddStreamBehavior(typeof(TImplementationType), serviceLifetime);
/// <summary>
/// Register a closed stream behavior type against all <see cref="IStreamPipelineBehavior{TRequest,TResponse}"/> implementations
/// </summary>
/// <param name="implementationType">Closed stream behavior implementation type</param>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddStreamBehavior(Type implementationType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
var implementedGenericInterfaces = implementationType.FindInterfacesThatClose(typeof(IStreamPipelineBehavior<,>)).ToList();
if (implementedGenericInterfaces.Count == 0)
{
throw new InvalidOperationException($"{implementationType.Name} must implement {typeof(IStreamPipelineBehavior<,>).FullName}");
}
foreach (var implementedBehaviorType in implementedGenericInterfaces)
{
StreamBehaviorsToRegister.Add(new ServiceDescriptor(implementedBehaviorType, implementationType, serviceLifetime));
}
return this;
}
/// <summary>
/// Registers an open stream behavior type against the <see cref="IStreamPipelineBehavior{TRequest,TResponse}"/> open generic interface type
/// </summary>
/// <param name="openBehaviorType">An open generic stream behavior type</param>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddOpenStreamBehavior(Type openBehaviorType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
if (!openBehaviorType.IsGenericType)
{
throw new InvalidOperationException($"{openBehaviorType.Name} must be generic");
}
var implementedGenericInterfaces = openBehaviorType.GetInterfaces().Where(i => i.IsGenericType).Select(i => i.GetGenericTypeDefinition());
var implementedOpenBehaviorInterfaces = new HashSet<Type>(implementedGenericInterfaces.Where(i => i == typeof(IStreamPipelineBehavior<,>)));
if (implementedOpenBehaviorInterfaces.Count == 0)
{
throw new InvalidOperationException($"{openBehaviorType.Name} must implement {typeof(IStreamPipelineBehavior<,>).FullName}");
}
foreach (var openBehaviorInterface in implementedOpenBehaviorInterfaces)
{
StreamBehaviorsToRegister.Add(new ServiceDescriptor(openBehaviorInterface, openBehaviorType, serviceLifetime));
}
return this;
}
/// <summary>
/// Register a closed request pre processor type
/// </summary>
/// <typeparam name="TServiceType">Closed request pre processor interface type</typeparam>
/// <typeparam name="TImplementationType">Closed request pre processor implementation type</typeparam>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddRequestPreProcessor<TServiceType, TImplementationType>(ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
=> AddRequestPreProcessor(typeof(TServiceType), typeof(TImplementationType), serviceLifetime);
/// <summary>
/// Register a closed request pre processor type
/// </summary>
/// <param name="serviceType">Closed request pre processor interface type</param>
/// <param name="implementationType">Closed request pre processor implementation type</param>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddRequestPreProcessor(Type serviceType, Type implementationType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
RequestPreProcessorsToRegister.Add(new ServiceDescriptor(serviceType, implementationType, serviceLifetime));
return this;
}
/// <summary>
/// Register a closed request pre processor type against all <see cref="IRequestPreProcessor{TRequest}"/> implementations
/// </summary>
/// <typeparam name="TImplementationType">Closed request pre processor implementation type</typeparam>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddRequestPreProcessor<TImplementationType>(
ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
=> AddRequestPreProcessor(typeof(TImplementationType), serviceLifetime);
/// <summary>
/// Register a closed request pre processor type against all <see cref="IRequestPreProcessor{TRequest}"/> implementations
/// </summary>
/// <param name="implementationType">Closed request pre processor implementation type</param>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddRequestPreProcessor(Type implementationType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
var implementedGenericInterfaces = implementationType.FindInterfacesThatClose(typeof(IRequestPreProcessor<>)).ToList();
if (implementedGenericInterfaces.Count == 0)
{
throw new InvalidOperationException($"{implementationType.Name} must implement {typeof(IRequestPreProcessor<>).FullName}");
}
foreach (var implementedPreProcessorType in implementedGenericInterfaces)
{
RequestPreProcessorsToRegister.Add(new ServiceDescriptor(implementedPreProcessorType, implementationType, serviceLifetime));
}
return this;
}
/// <summary>
/// Registers an open request pre processor type against the <see cref="IRequestPreProcessor{TRequest}"/> open generic interface type
/// </summary>
/// <param name="openBehaviorType">An open generic request pre processor type</param>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddOpenRequestPreProcessor(Type openBehaviorType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
if (!openBehaviorType.IsGenericType)
{
throw new InvalidOperationException($"{openBehaviorType.Name} must be generic");
}
var implementedGenericInterfaces = openBehaviorType.GetInterfaces().Where(i => i.IsGenericType).Select(i => i.GetGenericTypeDefinition());
var implementedOpenBehaviorInterfaces = new HashSet<Type>(implementedGenericInterfaces.Where(i => i == typeof(IRequestPreProcessor<>)));
if (implementedOpenBehaviorInterfaces.Count == 0)
{
throw new InvalidOperationException($"{openBehaviorType.Name} must implement {typeof(IRequestPreProcessor<>).FullName}");
}
foreach (var openBehaviorInterface in implementedOpenBehaviorInterfaces)
{
RequestPreProcessorsToRegister.Add(new ServiceDescriptor(openBehaviorInterface, openBehaviorType, serviceLifetime));
}
return this;
}
/// <summary>
/// Register a closed request post processor type
/// </summary>
/// <typeparam name="TServiceType">Closed request post processor interface type</typeparam>
/// <typeparam name="TImplementationType">Closed request post processor implementation type</typeparam>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddRequestPostProcessor<TServiceType, TImplementationType>(ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
=> AddRequestPostProcessor(typeof(TServiceType), typeof(TImplementationType), serviceLifetime);
/// <summary>
/// Register a closed request post processor type
/// </summary>
/// <param name="serviceType">Closed request post processor interface type</param>
/// <param name="implementationType">Closed request post processor implementation type</param>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddRequestPostProcessor(Type serviceType, Type implementationType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
RequestPostProcessorsToRegister.Add(new ServiceDescriptor(serviceType, implementationType, serviceLifetime));
return this;
}
/// <summary>
/// Register a closed request post processor type against all <see cref="IRequestPostProcessor{TRequest,TResponse}"/> implementations
/// </summary>
/// <typeparam name="TImplementationType">Closed request post processor implementation type</typeparam>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddRequestPostProcessor<TImplementationType>(ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
=> AddRequestPostProcessor(typeof(TImplementationType), serviceLifetime);
/// <summary>
/// Register a closed request post processor type against all <see cref="IRequestPostProcessor{TRequest,TResponse}"/> implementations
/// </summary>
/// <param name="implementationType">Closed request post processor implementation type</param>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddRequestPostProcessor(Type implementationType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
var implementedGenericInterfaces = implementationType.FindInterfacesThatClose(typeof(IRequestPostProcessor<,>)).ToList();
if (implementedGenericInterfaces.Count == 0)
{
throw new InvalidOperationException($"{implementationType.Name} must implement {typeof(IRequestPostProcessor<,>).FullName}");
}
foreach (var implementedPostProcessorType in implementedGenericInterfaces)
{
RequestPostProcessorsToRegister.Add(new ServiceDescriptor(implementedPostProcessorType, implementationType, serviceLifetime));
}
return this;
}
/// <summary>
/// Registers an open request post processor type against the <see cref="IRequestPostProcessor{TRequest,TResponse}"/> open generic interface type
/// </summary>
/// <param name="openBehaviorType">An open generic request post processor type</param>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddOpenRequestPostProcessor(Type openBehaviorType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
if (!openBehaviorType.IsGenericType)
{
throw new InvalidOperationException($"{openBehaviorType.Name} must be generic");
}
var implementedGenericInterfaces = openBehaviorType.GetInterfaces().Where(i => i.IsGenericType).Select(i => i.GetGenericTypeDefinition());
var implementedOpenBehaviorInterfaces = new HashSet<Type>(implementedGenericInterfaces.Where(i => i == typeof(IRequestPostProcessor<,>)));
if (implementedOpenBehaviorInterfaces.Count == 0)
{
throw new InvalidOperationException($"{openBehaviorType.Name} must implement {typeof(IRequestPostProcessor<,>).FullName}");
}
foreach (var openBehaviorInterface in implementedOpenBehaviorInterfaces)
{
RequestPostProcessorsToRegister.Add(new ServiceDescriptor(openBehaviorInterface, openBehaviorType, serviceLifetime));
}
return this;
}
}
================================================
FILE: src/MediatR/MicrosoftExtensionsDI/RequestExceptionActionProcessorStrategy.cs
================================================
namespace Microsoft.Extensions.DependencyInjection;
public enum RequestExceptionActionProcessorStrategy
{
ApplyForUnhandledExceptions,
ApplyForAllExceptions
}
================================================
FILE: src/MediatR/NotificationHandlerExecutor.cs
================================================
using System;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR;
public record NotificationHandlerExecutor(object HandlerInstance, Func<INotification, CancellationToken, Task> HandlerCallback);
================================================
FILE: src/MediatR/NotificationPublishers/ForeachAwaitPublisher.cs
================================================
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR.NotificationPublishers;
/// <summary>
/// Awaits each notification handler in a single foreach loop:
/// <code>
/// foreach (var handler in handlers) {
/// await handler(notification, cancellationToken);
/// }
/// </code>
/// </summary>
public class ForeachAwaitPublisher : INotificationPublisher
{
public async Task Publish(IEnumerable<NotificationHandlerExecutor> handlerExecutors, INotification notification, CancellationToken cancellationToken)
{
foreach (var handler in handlerExecutors)
{
await handler.HandlerCallback(notification, cancellationToken).ConfigureAwait(false);
}
}
}
================================================
FILE: src/MediatR/NotificationPublishers/TaskWhenAllPublisher.cs
================================================
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediatR.NotificationPublishers;
/// <summary>
/// Uses Task.WhenAll with the list of Handler tasks:
/// <code>
/// var tasks = handlers
/// .Select(handler => handler.Handle(notification, cancellationToken))
/// .ToList();
///
/// return Task.WhenAll(tasks);
/// </code>
/// </summary>
public class TaskWhenAllPublisher : INotificationPublisher
{
public Task Publish(IEnumerable<NotificationHandlerExecutor> handlerExecutors, INotification notification, CancellationToken cancellationToken)
{
var tasks = handlerExecutors
.Select(handler => handler.HandlerCallback(notification, cancellationToken))
.ToArray();
return Task.WhenAll(tasks);
}
}
================================================
FILE: src/MediatR/Pipeline/IRequestExceptionAction.cs
================================================
namespace MediatR.Pipeline;
using System;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Defines an exception action for a request
/// </summary>
/// <typeparam name="TRequest">Request type</typeparam>
/// <typeparam name="TException">Exception type</typeparam>
public interface IRequestExceptionAction<in TRequest, in TException>
where TRequest : notnull
where TException : Exception
{
/// <summary>
/// Called when the request handler throws an exception
/// </summary>
/// <param name="request">Request instance</param>
/// <param name="exception">The thrown exception</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>An awaitable task</returns>
Task Execute(TRequest request, TException exception, CancellationToken cancellationToken);
}
================================================
FILE: src/MediatR/Pipeline/IRequestExceptionHandler.cs
================================================
namespace MediatR.Pipeline;
using System;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Defines an exception handler for a request and response
/// </summary>
/// <typeparam name="TRequest">Request type</typeparam>
/// <typeparam name="TResponse">Response type</typeparam>
/// <typeparam name="TException">Exception type</typeparam>
public interface IRequestExceptionHandler<in TRequest, TResponse, in TException>
where TRequest : notnull
where TException : Exception
{
/// <summary>
/// Called when the request handler throws an exception
/// </summary>
/// <param name="request">Request instance</param>
/// <param name="exception">The thrown exception</param>
/// <param name="state">The current state of handling the exception</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>An awaitable task</returns>
Task Handle(TRequest request, TException exception, RequestExceptionHandlerState<TResponse> state, CancellationToken cancellationToken);
}
================================================
FILE: src/MediatR/Pipeline/IRequestPostProcessor.cs
================================================
namespace MediatR.Pipeline;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Defines a request post-processor for a request
/// </summary>
/// <typeparam name="TRequest">Request type</typeparam>
/// <typeparam name="TResponse">Response type</typeparam>
public interface IRequestPostProcessor<in TRequest, in TResponse> where TRequest : notnull
{
/// <summary>
/// Process method executes after the Handle method on your handler
/// </summary>
/// <param name="request">Request instance</param>
/// <param name="response">Response instance</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>An awaitable task</returns>
Task Process(TRequest request, TResponse response, CancellationToken cancellationToken);
}
================================================
FILE: src/MediatR/Pipeline/IRequestPreProcessor.cs
================================================
namespace MediatR.Pipeline;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Defined a request pre-processor for a handler
/// </summary>
/// <typeparam name="TRequest">Request type</typeparam>
public interface IRequestPreProcessor<in TRequest> where TRequest : notnull
{
/// <summary>
/// Process method executes before calling the Handle method on your handler
/// </summary>
/// <param name="request">Incoming request</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>An awaitable task</returns>
Task Process(TRequest request, CancellationToken cancellationToken);
}
================================================
FILE: src/MediatR/Pipeline/RequestExceptionActionProcessorBehavior.cs
================================================
namespace MediatR.Pipeline;
using Internal;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Behavior for executing all <see cref="IRequestExceptionAction{TRequest,TException}"/> instances
/// after an exception is thrown by the following pipeline steps
/// </summary>
/// <typeparam name="TRequest">Request type</typeparam>
/// <typeparam name="TResponse">Response type</typeparam>
public class RequestExceptionActionProcessorBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : notnull
{
private readonly IServiceProvider _serviceProvider;
public RequestExceptionActionProcessorBehavior(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider;
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
try
{
return await next(cancellationToken).ConfigureAwait(false);
}
catch (Exception exception)
{
var exceptionTypes = GetExceptionTypes(exception.GetType());
var actionsForException = exceptionTypes
.SelectMany(exceptionType => GetActionsForException(exceptionType, request))
.GroupBy(static actionForException => actionForException.Action.GetType())
.Select(static actionForException => actionForException.First())
.Select(static actionForException => (MethodInfo: GetMethodInfoForAction(actionForException.ExceptionType), actionForException.Action))
.ToList();
foreach (var actionForException in actionsForException)
{
try
{
await ((Task)(actionForException.MethodInfo.Invoke(actionForException.Action, new object[] { request, exception, cancellationToken })
?? throw new InvalidOperationException($"Could not create task for action method {actionForException.MethodInfo}."))).ConfigureAwait(false);
}
catch (TargetInvocationException invocationException) when (invocationException.InnerException != null)
{
// Unwrap invocation exception to throw the actual error
ExceptionDispatchInfo.Capture(invocationException.InnerException).Throw();
}
}
throw;
}
}
private static IEnumerable<Type> GetExceptionTypes(Type? exceptionType)
{
while (exceptionType != null && exceptionType != typeof(object))
{
yield return exceptionType;
exceptionType = exceptionType.BaseType;
}
}
private IEnumerable<(Type ExceptionType, object Action)> GetActionsForException(Type exceptionType, TRequest request)
{
var exceptionActionInterfaceType = typeof(IRequestExceptionAction<,>).MakeGenericType(typeof(TRequest), exceptionType);
var enumerableExceptionActionInterfaceType = typeof(IEnumerable<>).MakeGenericType(exceptionActionInterfaceType);
var actionsForException = (IEnumerable<object>)_serviceProvider.GetRequiredService(enumerableExceptionActionInterfaceType);
return HandlersOrderer.Prioritize(actionsForException.ToList(), request)
.Select(action => (exceptionType, action));
}
private static MethodInfo GetMethodInfoForAction(Type exceptionType)
{
var exceptionActionInterfaceType = typeof(IRequestExceptionAction<,>).MakeGenericType(typeof(TRequest), exceptionType);
var actionMethodInfo =
exceptionActionInterfaceType.GetMethod(nameof(IRequestExceptionAction<TRequest, Exception>.Execute))
?? throw new InvalidOperationException(
$"Could not find method {nameof(IRequestExceptionAction<TRequest, Exception>.Execute)} on type {exceptionActionInterfaceType}");
return actionMethodInfo;
}
}
================================================
FILE: src/MediatR/Pipeline/RequestExceptionHandlerState.cs
================================================
namespace MediatR.Pipeline;
/// <summary>
/// Represents the result of handling an exception thrown by a request handler
/// </summary>
/// <typeparam name="TResponse">Response type</typeparam>
public class RequestExceptionHandlerState<TResponse>
{
/// <summary>
/// Indicates whether the current exception has been handled and the response should be returned.
/// </summary>
public bool Handled { get; private set; }
/// <summary>
/// The response that is returned if <see cref="Handled"/> is <code>true</code>.
/// </summary>
public TResponse? Response { get; private set; }
/// <summary>
/// Call to indicate whether the current exception should be considered handled and the specified response should be returned.
/// </summary>
/// <param name="response">Set the response that will be returned.</param>
public void SetHandled(TResponse response)
{
Handled = true;
Response = response;
}
}
================================================
FILE: src/MediatR/Pipeline/RequestExceptionProcessorBehavior.cs
================================================
namespace MediatR.Pipeline;
using Internal;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Behavior for executing all <see cref="IRequestExceptionHandler{TRequest,TResponse,TException}"/> instances
/// after an exception is thrown by the following pipeline steps
/// </summary>
/// <typeparam name="TRequest">Request type</typeparam>
/// <typeparam name="TResponse">Response type</typeparam>
public class RequestExceptionProcessorBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : notnull
{
private readonly IServiceProvider _serviceProvider;
public RequestExceptionProcessorBehavior(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider;
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
try
{
return await next(cancellationToken).ConfigureAwait(false);
}
catch (Exception exception)
{
var state = new RequestExceptionHandlerState<TResponse>();
var exceptionTypes = GetExceptionTypes(exception.GetType());
var handlersForException = exceptionTypes
.SelectMany(exceptionType => GetHandlersForException(exceptionType, request))
.GroupBy(static handlerForException => handlerForException.Handler.GetType())
.Select(static handlerForException => handlerForException.First())
.Select(static handlerForException => (MethodInfo: GetMethodInfoForHandler(handlerForException.ExceptionType), handlerForException.Handler))
.ToList();
foreach (var handlerForException in handlersForException)
{
try
{
await ((Task) (handlerForException.MethodInfo.Invoke(handlerForException.Handler, new object[] { request, exception, state, cancellationToken })
?? throw new InvalidOperationException("Did not return a Task from the exception handler."))).ConfigureAwait(false);
}
catch (TargetInvocationException invocationException) when (invocationException.InnerException != null)
{
// Unwrap invocation exception to throw the actual error
ExceptionDispatchInfo.Capture(invocationException.InnerException).Throw();
}
if (state.Handled)
{
break;
}
}
if (!state.Handled)
{
throw;
}
if (state.Response is null)
{
throw;
}
return state.Response; //cannot be null if Handled
}
}
private static IEnumerable<Type> GetExceptionTypes(Type? exceptionType)
{
while (exceptionType != null && exceptionType != typeof(object))
{
yield return exceptionType;
exceptionType = exceptionType.BaseType;
}
}
private IEnumerable<(Type ExceptionType, object Handler)> GetHandlersForException(Type exceptionType, TRequest request)
{
var exceptionHandlerInterfaceType = typeof(IRequestExceptionHandler<,,>).MakeGenericType(typeof(TRequest), typeof(TResponse), exceptionType);
var enumerableExceptionHandlerInterfaceType = typeof(IEnumerable<>).MakeGenericType(exceptionHandlerInterfaceType);
var exceptionHandlers = (IEnumerable<object>) _serviceProvider.GetRequiredService(enumerableExceptionHandlerInterfaceType);
return HandlersOrderer.Prioritize(exceptionHandlers.ToList(), request)
.Select(handler => (exceptionType, action: handler));
}
private static MethodInfo GetMethodInfoForHandler(Type exceptionType)
{
var exceptionHandlerInterfaceType = typeof(IRequestExceptionHandler<,,>).MakeGenericType(typeof(TRequest), typeof(TResponse), exceptionType);
var handleMethodInfo = exceptionHandlerInterfaceType.GetMethod(nameof(IRequestExceptionHandler<TRequest, TResponse, Exception>.Handle))
?? throw new InvalidOperationException($"Could not find method {nameof(IRequestExceptionHandler<TRequest, TResponse, Exception>.Handle)} on type {exceptionHandlerInterfaceType}");
return handleMethodInfo;
}
}
================================================
FILE: src/MediatR/Pipeline/RequestPostProcessorBehavior.cs
================================================
namespace MediatR.Pipeline;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Behavior for executing all <see cref="IRequestPostProcessor{TRequest,TResponse}"/> instances after handling the request
/// </summary>
/// <typeparam name="TRequest">Request type</typeparam>
/// <typeparam name="TResponse">Response type</typeparam>
public class RequestPostProcessorBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : notnull
{
private readonly IEnumerable<IRequestPostProcessor<TRequest, TResponse>> _postProcessors;
public RequestPostProcessorBehavior(IEnumerable<IRequestPostProcessor<TRequest, TResponse>> postProcessors)
=> _postProcessors = postProcessors;
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
var response = await next(cancellationToken).ConfigureAwait(false);
foreach (var processor in _postProcessors)
{
await processor.Process(request, response, cancellationToken).ConfigureAwait(false);
}
return response;
}
}
================================================
FILE: src/MediatR/Pipeline/RequestPreProcessorB
gitextract_64igt8ai/
├── .editorconfig
├── .gitattributes
├── .github/
│ └── workflows/
│ ├── ci.yml
│ ├── release.yml
│ └── triage-issues.yml
├── .gitignore
├── Build.ps1
├── BuildContracts.ps1
├── Directory.Build.props
├── LICENSE.md
├── MediatR.slnx
├── MediatR.snk
├── NuGet.Config
├── Push.ps1
├── README.md
├── samples/
│ ├── MediatR.Examples/
│ │ ├── ConstrainedRequestPostProcessor.cs
│ │ ├── ExceptionHandler/
│ │ │ ├── Exceptions.cs
│ │ │ ├── ExceptionsHandlers.cs
│ │ │ ├── ExceptionsHandlersOverrides.cs
│ │ │ ├── Handlers.cs
│ │ │ ├── LogExceptionAction.cs
│ │ │ ├── Requests.cs
│ │ │ └── RequestsOverrides.cs
│ │ ├── GenericHandler.cs
│ │ ├── GenericPipelineBehavior.cs
│ │ ├── GenericRequestPostProcessor.cs
│ │ ├── GenericRequestPreProcessor.cs
│ │ ├── Jing.cs
│ │ ├── JingHandler.cs
│ │ ├── MediatR.Examples.csproj
│ │ ├── Ping.cs
│ │ ├── PingHandler.cs
│ │ ├── Pinged.cs
│ │ ├── PingedHandler.cs
│ │ ├── Pong.cs
│ │ ├── Ponged.cs
│ │ ├── Runner.cs
│ │ └── Streams/
│ │ ├── GenericStreamPipelineBehavior.cs
│ │ ├── Sing.cs
│ │ ├── SingHandler.cs
│ │ └── Song.cs
│ ├── MediatR.Examples.AspNetCore/
│ │ ├── MediatR.Examples.AspNetCore.csproj
│ │ └── Program.cs
│ ├── MediatR.Examples.Autofac/
│ │ ├── MediatR.Examples.Autofac.csproj
│ │ └── Program.cs
│ ├── MediatR.Examples.DryIoc/
│ │ ├── MediatR.Examples.DryIoc.csproj
│ │ └── Program.cs
│ ├── MediatR.Examples.Lamar/
│ │ ├── MediatR.Examples.Lamar.csproj
│ │ └── Program.cs
│ ├── MediatR.Examples.LightInject/
│ │ ├── MediatR.Examples.LightInject.csproj
│ │ └── Program.cs
│ ├── MediatR.Examples.PublishStrategies/
│ │ ├── AsyncPingedHandler.cs
│ │ ├── CustomMediator.cs
│ │ ├── MediatR.Examples.PublishStrategies.csproj
│ │ ├── Program.cs
│ │ ├── PublishStrategy.cs
│ │ ├── Publisher.cs
│ │ └── SyncPingedHandler.cs
│ ├── MediatR.Examples.SimpleInjector/
│ │ ├── MediatR.Examples.SimpleInjector.csproj
│ │ └── Program.cs
│ ├── MediatR.Examples.Stashbox/
│ │ ├── MediatR.Examples.Stashbox.csproj
│ │ └── Program.cs
│ └── MediatR.Examples.Windsor/
│ ├── ContravariantFilter.cs
│ ├── MediatR.Examples.Windsor.csproj
│ └── Program.cs
├── src/
│ ├── MediatR/
│ │ ├── Entities/
│ │ │ └── OpenBehavior.cs
│ │ ├── IMediator.cs
│ │ ├── INotificationHandler.cs
│ │ ├── INotificationPublisher.cs
│ │ ├── IPipelineBehavior.cs
│ │ ├── IPublisher.cs
│ │ ├── IRequestHandler.cs
│ │ ├── ISender.cs
│ │ ├── IStreamPipelineBehavior.cs
│ │ ├── IStreamRequestHandler.cs
│ │ ├── Internal/
│ │ │ ├── HandlersOrderer.cs
│ │ │ └── ObjectDetails.cs
│ │ ├── Licensing/
│ │ │ ├── BuildInfo.cs
│ │ │ ├── Edition.cs
│ │ │ ├── License.cs
│ │ │ ├── LicenseAccessor.cs
│ │ │ ├── LicenseValidator.cs
│ │ │ └── ProductType.cs
│ │ ├── MediatR.csproj
│ │ ├── Mediator.cs
│ │ ├── MicrosoftExtensionsDI/
│ │ │ ├── MediatRServiceCollectionExtensions.cs
│ │ │ ├── MediatrServiceConfiguration.cs
│ │ │ └── RequestExceptionActionProcessorStrategy.cs
│ │ ├── NotificationHandlerExecutor.cs
│ │ ├── NotificationPublishers/
│ │ │ ├── ForeachAwaitPublisher.cs
│ │ │ └── TaskWhenAllPublisher.cs
│ │ ├── Pipeline/
│ │ │ ├── IRequestExceptionAction.cs
│ │ │ ├── IRequestExceptionHandler.cs
│ │ │ ├── IRequestPostProcessor.cs
│ │ │ ├── IRequestPreProcessor.cs
│ │ │ ├── RequestExceptionActionProcessorBehavior.cs
│ │ │ ├── RequestExceptionHandlerState.cs
│ │ │ ├── RequestExceptionProcessorBehavior.cs
│ │ │ ├── RequestPostProcessorBehavior.cs
│ │ │ └── RequestPreProcessorBehavior.cs
│ │ ├── Registration/
│ │ │ └── ServiceRegistrar.cs
│ │ ├── TypeForwardings.cs
│ │ ├── Wrappers/
│ │ │ ├── NotificationHandlerWrapper.cs
│ │ │ ├── RequestHandlerWrapper.cs
│ │ │ └── StreamRequestHandlerWrapper.cs
│ │ └── license.txt
│ └── MediatR.Contracts/
│ ├── INotification.cs
│ ├── IRequest.cs
│ ├── IStreamRequest.cs
│ ├── MediatR.Contracts.csproj
│ └── Unit.cs
└── test/
├── MediatR.Benchmarks/
│ ├── Benchmarks.cs
│ ├── DotTraceDiagnoser.cs
│ ├── GenericPipelineBehavior.cs
│ ├── GenericRequestPostProcessor.cs
│ ├── GenericRequestPreProcessor.cs
│ ├── MediatR.Benchmarks.csproj
│ ├── Ping.cs
│ ├── Pinged.cs
│ └── Program.cs
├── MediatR.DependencyInjectionTests/
│ ├── Abstractions/
│ │ ├── BaseAssemblyResolutionTests.cs
│ │ └── BaseServiceProviderFixture.cs
│ ├── AutoFacDependencyInjectionTests.cs
│ ├── Contracts/
│ │ ├── Notifications/
│ │ │ └── Ding.cs
│ │ ├── Requests/
│ │ │ ├── InternalPing.cs
│ │ │ ├── InternalVoidPing.cs
│ │ │ ├── PrivatePing.cs
│ │ │ ├── PrivateVoidPing.cs
│ │ │ ├── PublicPing.cs
│ │ │ └── PublicVoidPing.cs
│ │ ├── Responses/
│ │ │ └── Pong.cs
│ │ └── StreamRequests/
│ │ ├── InternalZing.cs
│ │ ├── PrivateZing.cs
│ │ └── PublicZing.cs
│ ├── DryIocDependencyInjectionTests.cs
│ ├── LamarDependencyInjectionTests.cs
│ ├── LightInjectDependencyInjectionTests.cs
│ ├── MediatR.DependencyInjectionTests.csproj
│ ├── MicrosoftDependencyInjectionTests.cs
│ ├── Providers/
│ │ ├── AutoFacServiceProviderFixture.cs
│ │ ├── DryIocServiceProviderFixture.cs
│ │ ├── LamarServiceProviderFixture.cs
│ │ ├── LightInjectServiceProviderFixture.cs
│ │ ├── MicrosoftServiceProviderFixture.cs
│ │ └── StashBoxServiceProviderFixture.cs
│ ├── StashBoxDependencyInjectionTests.cs
│ └── Usings.cs
└── MediatR.Tests/
├── CreateStreamTests.cs
├── ExceptionTests.cs
├── GenericRequestHandlerTests.cs
├── GenericTypeConstraintsTests.cs
├── GlobalUsings.cs
├── Licensing/
│ └── LicenseValidatorTests.cs
├── MediatR.Tests.csproj
├── MicrosoftExtensionsDI/
│ ├── AssemblyResolutionTests.cs
│ ├── BaseGenericRequestHandlerTests.cs
│ ├── CustomMediatorTests.cs
│ ├── DerivingRequestsTests.cs
│ ├── DuplicateAssemblyResolutionTests.cs
│ ├── Handlers.cs
│ ├── Issue1118Tests.cs
│ ├── NotificationPublisherTests.cs
│ ├── PipeLineMultiCallToConstructorTest.cs
│ ├── PipelineTests.cs
│ ├── StreamPipelineTests.cs
│ ├── TypeEvaluatorTests.cs
│ └── TypeResolutionTests.cs
├── NotificationHandlerTests.cs
├── NotificationPublisherTests.cs
├── Pipeline/
│ ├── RequestExceptionActionTests.cs
│ ├── RequestExceptionHandlerTests.cs
│ ├── RequestPostProcessorTests.cs
│ ├── RequestPreProcessorTests.cs
│ └── Streams/
│ └── StreamPipelineBehaviorTests.cs
├── PipelineTests.cs
├── PublishTests.cs
├── SendTests.cs
├── SendVoidInterfaceTests.cs
├── ServiceFactoryTests.cs
├── StreamPipelineTests.cs
├── TestContainer.cs
└── UnitTests.cs
SYMBOL INDEX (1064 symbols across 145 files)
FILE: samples/MediatR.Examples.AspNetCore/Program.cs
class Program (line 10) | public static class Program
method Main (line 12) | public static Task Main(string[] args)
method BuildMediator (line 19) | private static IMediator BuildMediator(WrappingWriter writer)
FILE: samples/MediatR.Examples.Autofac/Program.cs
class Program (line 13) | internal static class Program
method Main (line 15) | public static Task Main(string[] args)
method BuildMediator (line 23) | private static IMediator BuildMediator(WrappingWriter writer)
FILE: samples/MediatR.Examples.DryIoc/Program.cs
class Program (line 10) | class Program
method Main (line 12) | static Task Main()
method BuildMediator (line 20) | private static IMediator BuildMediator(WrappingWriter writer)
FILE: samples/MediatR.Examples.Lamar/Program.cs
class Program (line 9) | class Program
method Main (line 11) | static Task Main(string[] args)
method BuildMediator (line 19) | private static IMediator BuildMediator(WrappingWriter writer)
FILE: samples/MediatR.Examples.LightInject/Program.cs
class Program (line 12) | class Program
method Main (line 14) | static Task Main(string[] args)
method BuildMediator (line 22) | private static IMediator BuildMediator(WrappingWriter writer)
FILE: samples/MediatR.Examples.PublishStrategies/AsyncPingedHandler.cs
class AsyncPingedHandler (line 7) | public class AsyncPingedHandler : INotificationHandler<Pinged>
method AsyncPingedHandler (line 9) | public AsyncPingedHandler(string name)
method Handle (line 16) | public async Task Handle(Pinged notification, CancellationToken cancel...
FILE: samples/MediatR.Examples.PublishStrategies/CustomMediator.cs
class CustomMediator (line 8) | public class CustomMediator : Mediator
method CustomMediator (line 12) | public CustomMediator(IServiceProvider serviceFactory, Func<IEnumerabl...
method PublishCore (line 15) | protected override Task PublishCore(IEnumerable<NotificationHandlerExe...
FILE: samples/MediatR.Examples.PublishStrategies/Program.cs
class Program (line 7) | class Program
method Main (line 9) | static async Task Main(string[] args)
FILE: samples/MediatR.Examples.PublishStrategies/PublishStrategy.cs
type PublishStrategy (line 6) | public enum PublishStrategy
FILE: samples/MediatR.Examples.PublishStrategies/Publisher.cs
class Publisher (line 9) | public class Publisher
method Publisher (line 13) | public Publisher(IServiceProvider serviceFactory)
method Publish (line 28) | public Task Publish<TNotification>(TNotification notification)
method Publish (line 33) | public Task Publish<TNotification>(TNotification notification, Publish...
method Publish (line 38) | public Task Publish<TNotification>(TNotification notification, Cancell...
method Publish (line 43) | public Task Publish<TNotification>(TNotification notification, Publish...
method ParallelWhenAll (line 53) | private Task ParallelWhenAll(IEnumerable<NotificationHandlerExecutor> ...
method ParallelWhenAny (line 65) | private Task ParallelWhenAny(IEnumerable<NotificationHandlerExecutor> ...
method ParallelNoWait (line 77) | private Task ParallelNoWait(IEnumerable<NotificationHandlerExecutor> h...
method AsyncContinueOnException (line 87) | private async Task AsyncContinueOnException(IEnumerable<NotificationHa...
method SyncStopOnException (line 123) | private async Task SyncStopOnException(IEnumerable<NotificationHandler...
method SyncContinueOnException (line 131) | private async Task SyncContinueOnException(IEnumerable<NotificationHan...
FILE: samples/MediatR.Examples.PublishStrategies/SyncPingedHandler.cs
class SyncPingedHandler (line 7) | public class SyncPingedHandler : INotificationHandler<Pinged>
method SyncPingedHandler (line 9) | public SyncPingedHandler(string name)
method Handle (line 16) | public Task Handle(Pinged notification, CancellationToken cancellation...
FILE: samples/MediatR.Examples.SimpleInjector/Program.cs
class Program (line 14) | internal static class Program
method Main (line 16) | private static Task Main(string[] args)
method BuildMediator (line 24) | private static IMediator BuildMediator(WrappingWriter writer)
method RegisterHandlers (line 69) | private static void RegisterHandlers(Container container, Type collect...
method GetAssemblies (line 81) | private static IEnumerable<Assembly> GetAssemblies()
FILE: samples/MediatR.Examples.Stashbox/Program.cs
class Program (line 10) | class Program
method Main (line 12) | static Task Main()
method BuildMediator (line 19) | private static IMediator BuildMediator(WrappingWriter writer)
FILE: samples/MediatR.Examples.Windsor/ContravariantFilter.cs
class ContravariantFilter (line 8) | public class ContravariantFilter : IHandlersFilter
method HasOpinionAbout (line 10) | public bool HasOpinionAbout(Type service)
method SelectHandlers (line 21) | public IHandler[] SelectHandlers(Type service, IHandler[] handlers)
FILE: samples/MediatR.Examples.Windsor/Program.cs
class Program (line 16) | internal class Program
method Main (line 18) | private static Task Main(string[] args)
method BuildMediator (line 26) | private static IMediator BuildMediator(WrappingWriter writer)
method ResolveRequestExceptionHandler (line 89) | private static object ResolveRequestExceptionHandler(IKernel k, Type t...
method ResolveRequestExceptionAction (line 125) | private static object ResolveRequestExceptionAction(IKernel k, Type ty...
method CreateArraysOutOfResolvedTypeAndEnumerableInterfaceTypes (line 160) | private static Array CreateArraysOutOfResolvedTypeAndEnumerableInterfa...
FILE: samples/MediatR.Examples/ConstrainedRequestPostProcessor.cs
class ConstrainedRequestPostProcessor (line 8) | public class ConstrainedRequestPostProcessor<TRequest, TResponse>
method ConstrainedRequestPostProcessor (line 14) | public ConstrainedRequestPostProcessor(TextWriter writer)
method Process (line 19) | public Task Process(TRequest request, TResponse response, Cancellation...
FILE: samples/MediatR.Examples/ExceptionHandler/Exceptions.cs
class ConnectionException (line 5) | public class ConnectionException : Exception { }
class ForbiddenException (line 7) | public class ForbiddenException : ConnectionException { }
class ResourceNotFoundException (line 9) | public class ResourceNotFoundException : ConnectionException { }
class ServerException (line 11) | public class ServerException : Exception { }
FILE: samples/MediatR.Examples/ExceptionHandler/ExceptionsHandlers.cs
class CommonExceptionHandler (line 9) | public class CommonExceptionHandler : IRequestExceptionHandler<PingResou...
method CommonExceptionHandler (line 13) | public CommonExceptionHandler(TextWriter writer) => _writer = writer;
method Handle (line 15) | public async Task Handle(PingResource request,
class ConnectionExceptionHandler (line 28) | public class ConnectionExceptionHandler : IRequestExceptionHandler<PingR...
method ConnectionExceptionHandler (line 32) | public ConnectionExceptionHandler(TextWriter writer) => _writer = writer;
method Handle (line 34) | public async Task Handle(PingResource request,
class AccessDeniedExceptionHandler (line 47) | public class AccessDeniedExceptionHandler : IRequestExceptionHandler<Pin...
method AccessDeniedExceptionHandler (line 51) | public AccessDeniedExceptionHandler(TextWriter writer) => _writer = wr...
method Handle (line 53) | public async Task Handle(PingResource request,
class ServerExceptionHandler (line 66) | public class ServerExceptionHandler : IRequestExceptionHandler<PingNewRe...
method ServerExceptionHandler (line 70) | public ServerExceptionHandler(TextWriter writer) => _writer = writer;
method Handle (line 72) | public virtual async Task Handle(PingNewResource request,
FILE: samples/MediatR.Examples/ExceptionHandler/ExceptionsHandlersOverrides.cs
class CommonExceptionHandler (line 9) | public class CommonExceptionHandler : IRequestExceptionHandler<PingResou...
method CommonExceptionHandler (line 13) | public CommonExceptionHandler(TextWriter writer) => _writer = writer;
method Handle (line 15) | public async Task Handle(PingResourceTimeout request,
class ServerExceptionHandler (line 28) | public class ServerExceptionHandler : ExceptionHandler.ServerExceptionHa...
method ServerExceptionHandler (line 32) | public ServerExceptionHandler(TextWriter writer) : base(writer) => _wr...
method Handle (line 34) | public override async Task Handle(PingNewResource request,
FILE: samples/MediatR.Examples/ExceptionHandler/Handlers.cs
class PingResourceHandler (line 7) | public class PingResourceHandler : IRequestHandler<PingResource, Pong>
method PingResourceHandler (line 11) | public PingResourceHandler(TextWriter writer) => _writer = writer;
method Handle (line 13) | public Task<Pong> Handle(PingResource request, CancellationToken cance...
class PingNewResourceHandler (line 19) | public class PingNewResourceHandler : IRequestHandler<PingNewResource, P...
method PingNewResourceHandler (line 23) | public PingNewResourceHandler(TextWriter writer) => _writer = writer;
method Handle (line 25) | public Task<Pong> Handle(PingNewResource request, CancellationToken ca...
class PingResourceTimeoutHandler (line 31) | public class PingResourceTimeoutHandler : IRequestHandler<PingResourceTi...
method PingResourceTimeoutHandler (line 35) | public PingResourceTimeoutHandler(TextWriter writer) => _writer = writer;
method Handle (line 37) | public Task<Pong> Handle(PingResourceTimeout request, CancellationToke...
class PingResourceTimeoutOverrideHandler (line 43) | public class PingResourceTimeoutOverrideHandler : IRequestHandler<Overri...
method PingResourceTimeoutOverrideHandler (line 47) | public PingResourceTimeoutOverrideHandler(TextWriter writer) => _write...
method Handle (line 49) | public Task<Pong> Handle(Overrides.PingResourceTimeout request, Cancel...
class PingProtectedResourceHandler (line 55) | public class PingProtectedResourceHandler : IRequestHandler<PingProtecte...
method PingProtectedResourceHandler (line 59) | public PingProtectedResourceHandler(TextWriter writer) => _writer = wr...
method Handle (line 61) | public Task<Pong> Handle(PingProtectedResource request, CancellationTo...
FILE: samples/MediatR.Examples/ExceptionHandler/LogExceptionAction.cs
class LogExceptionAction (line 9) | public class LogExceptionAction : IRequestExceptionAction<Ping, Exception>
method LogExceptionAction (line 13) | public LogExceptionAction(TextWriter writer) => _writer = writer;
method Execute (line 15) | public Task Execute(Ping request, Exception exception, CancellationTok...
FILE: samples/MediatR.Examples/ExceptionHandler/Requests.cs
class PingResource (line 3) | public class PingResource : Ping { }
class PingNewResource (line 5) | public class PingNewResource : Ping { }
class PingResourceTimeout (line 7) | public class PingResourceTimeout : PingResource { }
class PingProtectedResource (line 9) | public class PingProtectedResource : PingResource { }
FILE: samples/MediatR.Examples/ExceptionHandler/RequestsOverrides.cs
class PingResourceTimeout (line 3) | public class PingResourceTimeout : ExceptionHandler.PingResourceTimeout { }
FILE: samples/MediatR.Examples/GenericHandler.cs
class GenericHandler (line 7) | public class GenericHandler : INotificationHandler<INotification>
method GenericHandler (line 11) | public GenericHandler(TextWriter writer)
method Handle (line 16) | public Task Handle(INotification notification, CancellationToken cance...
FILE: samples/MediatR.Examples/GenericPipelineBehavior.cs
class GenericPipelineBehavior (line 7) | public class GenericPipelineBehavior<TRequest, TResponse> : IPipelineBeh...
method GenericPipelineBehavior (line 11) | public GenericPipelineBehavior(TextWriter writer)
method Handle (line 16) | public async Task<TResponse> Handle(TRequest request, RequestHandlerDe...
FILE: samples/MediatR.Examples/GenericRequestPostProcessor.cs
class GenericRequestPostProcessor (line 8) | public class GenericRequestPostProcessor<TRequest, TResponse> : IRequest...
method GenericRequestPostProcessor (line 12) | public GenericRequestPostProcessor(TextWriter writer)
method Process (line 17) | public Task Process(TRequest request, TResponse response, Cancellation...
FILE: samples/MediatR.Examples/GenericRequestPreProcessor.cs
class GenericRequestPreProcessor (line 8) | public class GenericRequestPreProcessor<TRequest> : IRequestPreProcessor...
method GenericRequestPreProcessor (line 12) | public GenericRequestPreProcessor(TextWriter writer)
method Process (line 17) | public Task Process(TRequest request, CancellationToken cancellationTo...
FILE: samples/MediatR.Examples/Jing.cs
class Jing (line 3) | public class Jing : IRequest
FILE: samples/MediatR.Examples/JingHandler.cs
class JingHandler (line 7) | public class JingHandler : IRequestHandler<Jing>
method JingHandler (line 11) | public JingHandler(TextWriter writer)
method Handle (line 16) | public Task Handle(Jing request, CancellationToken cancellationToken)
FILE: samples/MediatR.Examples/Ping.cs
class Ping (line 3) | public class Ping : IRequest<Pong>
FILE: samples/MediatR.Examples/PingHandler.cs
class PingHandler (line 8) | public class PingHandler : IRequestHandler<Ping, Pong>
method PingHandler (line 12) | public PingHandler(TextWriter writer)
method Handle (line 17) | public async Task<Pong> Handle(Ping request, CancellationToken cancell...
FILE: samples/MediatR.Examples/Pinged.cs
class Pinged (line 3) | public class Pinged : INotification
FILE: samples/MediatR.Examples/PingedHandler.cs
class PingedHandler (line 8) | public class PingedHandler : INotificationHandler<Pinged>
method PingedHandler (line 12) | public PingedHandler(TextWriter writer)
method Handle (line 17) | public Task Handle(Pinged notification, CancellationToken cancellation...
class PongedHandler (line 23) | public class PongedHandler : INotificationHandler<Ponged>
method PongedHandler (line 27) | public PongedHandler(TextWriter writer)
method Handle (line 32) | public Task Handle(Ponged notification, CancellationToken cancellation...
class ConstrainedPingedHandler (line 38) | public class ConstrainedPingedHandler<TNotification> : INotificationHand...
method ConstrainedPingedHandler (line 43) | public ConstrainedPingedHandler(TextWriter writer)
method Handle (line 48) | public Task Handle(TNotification notification, CancellationToken cance...
class PingedAlsoHandler (line 54) | public class PingedAlsoHandler : INotificationHandler<Pinged>
method PingedAlsoHandler (line 58) | public PingedAlsoHandler(TextWriter writer)
method Handle (line 63) | public Task Handle(Pinged notification, CancellationToken cancellation...
FILE: samples/MediatR.Examples/Pong.cs
class Pong (line 3) | public class Pong
FILE: samples/MediatR.Examples/Ponged.cs
class Ponged (line 3) | public class Ponged : INotification
FILE: samples/MediatR.Examples/Runner.cs
class Runner (line 11) | public static class Runner
method Run (line 13) | public static async Task Run(IMediator mediator, WrappingWriter writer...
method IsHandlerForSameExceptionWorks (line 182) | private static async Task<bool> IsHandlerForSameExceptionWorks(IMediat...
method IsHandlerForBaseExceptionWorks (line 201) | private static async Task<bool> IsHandlerForBaseExceptionWorks(IMediat...
method IsHandlerForLessSpecificExceptionWorks (line 220) | private static async Task<bool> IsHandlerForLessSpecificExceptionWorks...
method IsPreferredHandlerForBaseExceptionWorks (line 239) | private static async Task<bool> IsPreferredHandlerForBaseExceptionWork...
method IsOverriddenHandlerForBaseExceptionWorks (line 259) | private static async Task<bool> IsOverriddenHandlerForBaseExceptionWor...
method IsExceptionHandledBy (line 279) | private static bool IsExceptionHandledBy<TException, THandler>(Wrappin...
class RunResults (line 293) | public class RunResults
class WrappingWriter (line 318) | public class WrappingWriter : TextWriter
method WrappingWriter (line 323) | public WrappingWriter(TextWriter innerWriter)
method Write (line 328) | public override void Write(char value)
method WriteLineAsync (line 334) | public override Task WriteLineAsync(string value)
FILE: samples/MediatR.Examples/Streams/GenericStreamPipelineBehavior.cs
class GenericStreamPipelineBehavior (line 9) | public class GenericStreamPipelineBehavior<TRequest, TResponse> : IStrea...
method GenericStreamPipelineBehavior (line 13) | public GenericStreamPipelineBehavior(TextWriter writer)
method Handle (line 18) | public async IAsyncEnumerable<TResponse> Handle(TRequest request, Stre...
FILE: samples/MediatR.Examples/Streams/Sing.cs
class Sing (line 3) | public class Sing : IStreamRequest<Song>
FILE: samples/MediatR.Examples/Streams/SingHandler.cs
class SingHandler (line 9) | public class SingHandler : IStreamRequestHandler<Sing, Song>
method SingHandler (line 13) | public SingHandler(TextWriter writer)
method Handle (line 18) | public async IAsyncEnumerable<Song> Handle(Sing request, [EnumeratorCa...
FILE: samples/MediatR.Examples/Streams/Song.cs
class Song (line 3) | public class Song
FILE: src/MediatR.Contracts/INotification.cs
type INotification (line 6) | public interface INotification { }
FILE: src/MediatR.Contracts/IRequest.cs
type IRequest (line 6) | public interface IRequest : IBaseRequest { }
type IRequest (line 12) | public interface IRequest<out TResponse> : IBaseRequest { }
type IBaseRequest (line 17) | public interface IBaseRequest { }
FILE: src/MediatR.Contracts/IStreamRequest.cs
type IStreamRequest (line 7) | public interface IStreamRequest<out TResponse> { }
FILE: src/MediatR.Contracts/Unit.cs
type Unit (line 9) | public readonly struct Unit : IEquatable<Unit>, IComparable<Unit>, IComp...
method CompareTo (line 34) | public int CompareTo(Unit other) => 0;
method CompareTo (line 47) | int IComparable.CompareTo(object? obj) => 0;
method GetHashCode (line 55) | public override int GetHashCode() => 0;
method Equals (line 64) | public bool Equals(Unit other) => true;
method Equals (line 73) | public override bool Equals(object? obj) => obj is Unit;
method ToString (line 95) | public override string ToString() => "()";
FILE: src/MediatR/Entities/OpenBehavior.cs
class OpenBehavior (line 9) | public class OpenBehavior
method OpenBehavior (line 18) | public OpenBehavior(Type openBehaviorType, ServiceLifetime serviceLife...
method ValidatePipelineBehaviorType (line 41) | private static void ValidatePipelineBehaviorType(Type openBehaviorType)
FILE: src/MediatR/IMediator.cs
type IMediator (line 6) | public interface IMediator : ISender, IPublisher
FILE: src/MediatR/INotificationHandler.cs
type INotificationHandler (line 10) | public interface INotificationHandler<in TNotification>
method Handle (line 18) | Task Handle(TNotification notification, CancellationToken cancellation...
class NotificationHandler (line 25) | public abstract class NotificationHandler<TNotification> : INotification...
method Handle (line 28) | Task INotificationHandler<TNotification>.Handle(TNotification notifica...
method Handle (line 39) | protected abstract void Handle(TNotification notification);
FILE: src/MediatR/INotificationPublisher.cs
type INotificationPublisher (line 7) | public interface INotificationPublisher
method Publish (line 9) | Task Publish(IEnumerable<NotificationHandlerExecutor> handlerExecutors...
FILE: src/MediatR/IPipelineBehavior.cs
type IPipelineBehavior (line 20) | public interface IPipelineBehavior<in TRequest, TResponse> where TReques...
method Handle (line 29) | Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TRespo...
FILE: src/MediatR/IPublisher.cs
type IPublisher (line 9) | public interface IPublisher
method Publish (line 17) | Task Publish(object notification, CancellationToken cancellationToken ...
method Publish (line 25) | Task Publish<TNotification>(TNotification notification, CancellationTo...
FILE: src/MediatR/IRequestHandler.cs
type IRequestHandler (line 11) | public interface IRequestHandler<in TRequest, TResponse>
method Handle (line 20) | Task<TResponse> Handle(TRequest request, CancellationToken cancellatio...
method Handle (line 36) | Task Handle(TRequest request, CancellationToken cancellationToken);
type IRequestHandler (line 27) | public interface IRequestHandler<in TRequest>
method Handle (line 20) | Task<TResponse> Handle(TRequest request, CancellationToken cancellatio...
method Handle (line 36) | Task Handle(TRequest request, CancellationToken cancellationToken);
FILE: src/MediatR/ISender.cs
type ISender (line 10) | public interface ISender
method Send (line 19) | Task<TResponse> Send<TResponse>(IRequest<TResponse> request, Cancellat...
method Send (line 27) | Task Send<TRequest>(TRequest request, CancellationToken cancellationTo...
method Send (line 36) | Task<object?> Send(object request, CancellationToken cancellationToken...
method CreateStream (line 45) | IAsyncEnumerable<TResponse> CreateStream<TResponse>(IStreamRequest<TRe...
method CreateStream (line 53) | IAsyncEnumerable<object?> CreateStream(object request, CancellationTok...
FILE: src/MediatR/IStreamPipelineBehavior.cs
type IStreamPipelineBehavior (line 20) | public interface IStreamPipelineBehavior<in TRequest, TResponse> where T...
method Handle (line 29) | IAsyncEnumerable<TResponse> Handle(TRequest request, StreamHandlerDele...
FILE: src/MediatR/IStreamRequestHandler.cs
type IStreamRequestHandler (line 11) | public interface IStreamRequestHandler<in TRequest, out TResponse>
method Handle (line 20) | IAsyncEnumerable<TResponse> Handle(TRequest request, CancellationToken...
FILE: src/MediatR/Internal/HandlersOrderer.cs
class HandlersOrderer (line 7) | internal static class HandlersOrderer
method Prioritize (line 9) | public static IList<object> Prioritize<TRequest>(IList<object> handler...
method RemoveOverridden (line 26) | private static IEnumerable<ObjectDetails> RemoveOverridden(IList<Objec...
FILE: src/MediatR/Internal/ObjectDetails.cs
class ObjectDetails (line 6) | internal class ObjectDetails : IComparer<ObjectDetails>
method ObjectDetails (line 20) | public ObjectDetails(object value)
method Compare (line 31) | public int Compare(ObjectDetails? x, ObjectDetails? y)
method CompareByAssembly (line 56) | private int? CompareByAssembly(ObjectDetails x, ObjectDetails y)
method CompareByNamespace (line 85) | private int? CompareByNamespace(ObjectDetails x, ObjectDetails y)
method CompareByLocation (line 119) | private int CompareByLocation(ObjectDetails x, ObjectDetails y)
FILE: src/MediatR/Licensing/BuildInfo.cs
class BuildInfo (line 7) | internal static class BuildInfo
method GetBuildDate (line 11) | private static DateTimeOffset? GetBuildDate()
FILE: src/MediatR/Licensing/Edition.cs
type Edition (line 3) | internal enum Edition
FILE: src/MediatR/Licensing/License.cs
class License (line 7) | internal class License
method License (line 9) | internal License(params Claim[] claims) : this(new ClaimsPrincipal(new...
method License (line 14) | public License(ClaimsPrincipal claims)
FILE: src/MediatR/Licensing/LicenseAccessor.cs
class LicenseAccessor (line 14) | internal class LicenseAccessor
method LicenseAccessor (line 19) | public LicenseAccessor(MediatRServiceConfiguration configuration, ILog...
method LicenseAccessor (line 25) | public LicenseAccessor(ILoggerFactory loggerFactory)
method Initialize (line 35) | private License Initialize()
method ValidateKey (line 60) | private Claim[] ValidateKey(string licenseKey)
FILE: src/MediatR/Licensing/LicenseValidator.cs
class LicenseValidator (line 7) | internal class LicenseValidator
method LicenseValidator (line 12) | public LicenseValidator(ILoggerFactory loggerFactory) : this(loggerFac...
method LicenseValidator (line 16) | public LicenseValidator(ILoggerFactory loggerFactory, DateTimeOffset? ...
method Validate (line 22) | public void Validate(License license)
FILE: src/MediatR/Licensing/ProductType.cs
type ProductType (line 3) | internal enum ProductType
FILE: src/MediatR/Mediator.cs
class Mediator (line 17) | public class Mediator : IMediator
method Mediator (line 29) | public Mediator(IServiceProvider serviceProvider)
method Mediator (line 37) | public Mediator(IServiceProvider serviceProvider, INotificationPublish...
method Send (line 50) | public Task<TResponse> Send<TResponse>(IRequest<TResponse> request, Ca...
method Send (line 67) | public Task Send<TRequest>(TRequest request, CancellationToken cancell...
method Send (line 85) | public Task<object?> Send(object request, CancellationToken cancellati...
method Publish (line 121) | public Task Publish<TNotification>(TNotification notification, Cancell...
method Publish (line 132) | public Task Publish(object notification, CancellationToken cancellatio...
method PublishCore (line 147) | protected virtual Task PublishCore(IEnumerable<NotificationHandlerExec...
method PublishNotification (line 150) | private Task PublishNotification(INotification notification, Cancellat...
method CreateStream (line 163) | public IAsyncEnumerable<TResponse> CreateStream<TResponse>(IStreamRequ...
method CreateStream (line 183) | public IAsyncEnumerable<object?> CreateStream(object request, Cancella...
FILE: src/MediatR/MicrosoftExtensionsDI/MediatRServiceCollectionExtensions.cs
class MediatRServiceCollectionExtensions (line 20) | public static class MediatRServiceCollectionExtensions
method AddMediatR (line 28) | public static IServiceCollection AddMediatR(this IServiceCollection se...
method AddMediatR (line 44) | public static IServiceCollection AddMediatR(this IServiceCollection se...
method CheckLicense (line 61) | internal static void CheckLicense(this IServiceProvider serviceProvider)
FILE: src/MediatR/MicrosoftExtensionsDI/MediatrServiceConfiguration.cs
class MediatRServiceConfiguration (line 13) | public class MediatRServiceConfiguration
method RegisterServicesFromAssemblyContaining (line 108) | public MediatRServiceConfiguration RegisterServicesFromAssemblyContain...
method RegisterServicesFromAssemblyContaining (line 116) | public MediatRServiceConfiguration RegisterServicesFromAssemblyContain...
method RegisterServicesFromAssembly (line 124) | public MediatRServiceConfiguration RegisterServicesFromAssembly(Assemb...
method RegisterServicesFromAssemblies (line 136) | public MediatRServiceConfiguration RegisterServicesFromAssemblies(
method AddBehavior (line 151) | public MediatRServiceConfiguration AddBehavior<TServiceType, TImplemen...
method AddBehavior (line 160) | public MediatRServiceConfiguration AddBehavior<TImplementationType>(Se...
method AddBehavior (line 171) | public MediatRServiceConfiguration AddBehavior(Type implementationType...
method AddBehavior (line 195) | public MediatRServiceConfiguration AddBehavior(Type serviceType, Type ...
method AddOpenBehavior (line 208) | public MediatRServiceConfiguration AddOpenBehavior(Type openBehaviorTy...
method AddOpenBehaviors (line 237) | public MediatRServiceConfiguration AddOpenBehaviors(IEnumerable<Type> ...
method AddOpenBehaviors (line 252) | public MediatRServiceConfiguration AddOpenBehaviors(IEnumerable<OpenBe...
method AddStreamBehavior (line 269) | public MediatRServiceConfiguration AddStreamBehavior<TServiceType, TIm...
method AddStreamBehavior (line 279) | public MediatRServiceConfiguration AddStreamBehavior(Type serviceType,...
method AddStreamBehavior (line 292) | public MediatRServiceConfiguration AddStreamBehavior<TImplementationTy...
method AddStreamBehavior (line 301) | public MediatRServiceConfiguration AddStreamBehavior(Type implementati...
method AddOpenStreamBehavior (line 324) | public MediatRServiceConfiguration AddOpenStreamBehavior(Type openBeha...
method AddRequestPreProcessor (line 354) | public MediatRServiceConfiguration AddRequestPreProcessor<TServiceType...
method AddRequestPreProcessor (line 364) | public MediatRServiceConfiguration AddRequestPreProcessor(Type service...
method AddRequestPreProcessor (line 377) | public MediatRServiceConfiguration AddRequestPreProcessor<TImplementat...
method AddRequestPreProcessor (line 387) | public MediatRServiceConfiguration AddRequestPreProcessor(Type impleme...
method AddOpenRequestPreProcessor (line 410) | public MediatRServiceConfiguration AddOpenRequestPreProcessor(Type ope...
method AddRequestPostProcessor (line 440) | public MediatRServiceConfiguration AddRequestPostProcessor<TServiceTyp...
method AddRequestPostProcessor (line 450) | public MediatRServiceConfiguration AddRequestPostProcessor(Type servic...
method AddRequestPostProcessor (line 463) | public MediatRServiceConfiguration AddRequestPostProcessor<TImplementa...
method AddRequestPostProcessor (line 472) | public MediatRServiceConfiguration AddRequestPostProcessor(Type implem...
method AddOpenRequestPostProcessor (line 494) | public MediatRServiceConfiguration AddOpenRequestPostProcessor(Type op...
FILE: src/MediatR/MicrosoftExtensionsDI/RequestExceptionActionProcessorStrategy.cs
type RequestExceptionActionProcessorStrategy (line 3) | public enum RequestExceptionActionProcessorStrategy
FILE: src/MediatR/NotificationHandlerExecutor.cs
type NotificationHandlerExecutor (line 7) | public record NotificationHandlerExecutor(object HandlerInstance, Func<I...
FILE: src/MediatR/NotificationPublishers/ForeachAwaitPublisher.cs
class ForeachAwaitPublisher (line 15) | public class ForeachAwaitPublisher : INotificationPublisher
method Publish (line 17) | public async Task Publish(IEnumerable<NotificationHandlerExecutor> han...
FILE: src/MediatR/NotificationPublishers/TaskWhenAllPublisher.cs
class TaskWhenAllPublisher (line 18) | public class TaskWhenAllPublisher : INotificationPublisher
method Publish (line 20) | public Task Publish(IEnumerable<NotificationHandlerExecutor> handlerEx...
FILE: src/MediatR/Pipeline/IRequestExceptionAction.cs
type IRequestExceptionAction (line 12) | public interface IRequestExceptionAction<in TRequest, in TException>
method Execute (line 23) | Task Execute(TRequest request, TException exception, CancellationToken...
FILE: src/MediatR/Pipeline/IRequestExceptionHandler.cs
type IRequestExceptionHandler (line 13) | public interface IRequestExceptionHandler<in TRequest, TResponse, in TEx...
method Handle (line 25) | Task Handle(TRequest request, TException exception, RequestExceptionHa...
FILE: src/MediatR/Pipeline/IRequestPostProcessor.cs
type IRequestPostProcessor (line 11) | public interface IRequestPostProcessor<in TRequest, in TResponse> where ...
method Process (line 20) | Task Process(TRequest request, TResponse response, CancellationToken c...
FILE: src/MediatR/Pipeline/IRequestPreProcessor.cs
type IRequestPreProcessor (line 10) | public interface IRequestPreProcessor<in TRequest> where TRequest : notnull
method Process (line 18) | Task Process(TRequest request, CancellationToken cancellationToken);
FILE: src/MediatR/Pipeline/RequestExceptionActionProcessorBehavior.cs
class RequestExceptionActionProcessorBehavior (line 19) | public class RequestExceptionActionProcessorBehavior<TRequest, TResponse...
method RequestExceptionActionProcessorBehavior (line 24) | public RequestExceptionActionProcessorBehavior(IServiceProvider servic...
method Handle (line 26) | public async Task<TResponse> Handle(TRequest request, RequestHandlerDe...
method GetExceptionTypes (line 61) | private static IEnumerable<Type> GetExceptionTypes(Type? exceptionType)
method GetActionsForException (line 70) | private IEnumerable<(Type ExceptionType, object Action)> GetActionsFor...
method GetMethodInfoForAction (line 81) | private static MethodInfo GetMethodInfoForAction(Type exceptionType)
FILE: src/MediatR/Pipeline/RequestExceptionHandlerState.cs
class RequestExceptionHandlerState (line 7) | public class RequestExceptionHandlerState<TResponse>
method SetHandled (line 23) | public void SetHandled(TResponse response)
FILE: src/MediatR/Pipeline/RequestExceptionProcessorBehavior.cs
class RequestExceptionProcessorBehavior (line 19) | public class RequestExceptionProcessorBehavior<TRequest, TResponse> : IP...
method RequestExceptionProcessorBehavior (line 24) | public RequestExceptionProcessorBehavior(IServiceProvider serviceProvi...
method Handle (line 26) | public async Task<TResponse> Handle(TRequest request, RequestHandlerDe...
method GetExceptionTypes (line 77) | private static IEnumerable<Type> GetExceptionTypes(Type? exceptionType)
method GetHandlersForException (line 86) | private IEnumerable<(Type ExceptionType, object Handler)> GetHandlersF...
method GetMethodInfoForHandler (line 97) | private static MethodInfo GetMethodInfoForHandler(Type exceptionType)
FILE: src/MediatR/Pipeline/RequestPostProcessorBehavior.cs
class RequestPostProcessorBehavior (line 12) | public class RequestPostProcessorBehavior<TRequest, TResponse> : IPipeli...
method RequestPostProcessorBehavior (line 17) | public RequestPostProcessorBehavior(IEnumerable<IRequestPostProcessor<...
method Handle (line 20) | public async Task<TResponse> Handle(TRequest request, RequestHandlerDe...
FILE: src/MediatR/Pipeline/RequestPreProcessorBehavior.cs
class RequestPreProcessorBehavior (line 12) | public class RequestPreProcessorBehavior<TRequest, TResponse> : IPipelin...
method RequestPreProcessorBehavior (line 17) | public RequestPreProcessorBehavior(IEnumerable<IRequestPreProcessor<TR...
method Handle (line 20) | public async Task<TResponse> Handle(TRequest request, RequestHandlerDe...
FILE: src/MediatR/Registration/ServiceRegistrar.cs
class ServiceRegistrar (line 14) | public static class ServiceRegistrar
method SetGenericRequestHandlerRegistrationLimitations (line 21) | public static void SetGenericRequestHandlerRegistrationLimitations(Med...
method AddMediatRClassesWithTimeout (line 29) | public static void AddMediatRClassesWithTimeout(IServiceCollection ser...
method AddMediatRClasses (line 44) | public static void AddMediatRClasses(IServiceCollection services, Medi...
method ConnectImplementationsToTypesClosing (line 94) | private static void ConnectImplementationsToTypesClosing(Type openRequ...
method IsMatchingWithInterface (line 172) | private static bool IsMatchingWithInterface(Type? handlerType, Type ha...
method AddConcretionsThatCouldBeClosed (line 194) | private static void AddConcretionsThatCouldBeClosed(Type @interface, L...
method GetConcreteRegistrationTypes (line 209) | private static (Type Service, Type Implementation) GetConcreteRegistra...
method GetConcreteRequestTypes (line 227) | private static List<Type>? GetConcreteRequestTypes(Type openRequestHan...
method GenerateCombinations (line 254) | public static List<List<Type>> GenerateCombinations(Type requestType, ...
method AddAllConcretionsThatClose (line 300) | private static void AddAllConcretionsThatClose(Type openRequestInterfa...
method CouldCloseTo (line 320) | internal static bool CouldCloseTo(this Type openConcretion, Type close...
method CanBeCastTo (line 329) | private static bool CanBeCastTo(this Type pluggedType, Type pluginType)
method IsOpenGeneric (line 338) | private static bool IsOpenGeneric(this Type type)
method FindInterfacesThatClose (line 343) | internal static IEnumerable<Type> FindInterfacesThatClose(this Type pl...
method FindInterfacesThatClosesCore (line 348) | private static IEnumerable<Type> FindInterfacesThatClosesCore(Type plu...
method IsConcrete (line 378) | private static bool IsConcrete(this Type type)
method Fill (line 383) | private static void Fill<T>(this IList<T> list, T value)
method GetLoadableDefinedTypes (line 389) | private static IEnumerable<Type> GetLoadableDefinedTypes(this Assembly...
method HasNestedGenericResponseType (line 401) | private static bool HasNestedGenericResponseType(Type openBehaviorType)
method TryMatchType (line 409) | private static bool TryMatchType(Type pattern, Type concrete, Dictiona...
method RegisterClosedBehaviorsFromAssemblies (line 428) | private static void RegisterClosedBehaviorsFromAssemblies(
method AddRequiredServices (line 464) | public static void AddRequiredServices(IServiceCollection services, Me...
method RegisterBehaviorIfImplementationsExist (line 550) | private static void RegisterBehaviorIfImplementationsExist(IServiceCol...
FILE: src/MediatR/Wrappers/NotificationHandlerWrapper.cs
class NotificationHandlerWrapper (line 10) | public abstract class NotificationHandlerWrapper
method Handle (line 12) | public abstract Task Handle(INotification notification, IServiceProvid...
class NotificationHandlerWrapperImpl (line 17) | public class NotificationHandlerWrapperImpl<TNotification> : Notificatio...
method Handle (line 20) | public override Task Handle(INotification notification, IServiceProvid...
FILE: src/MediatR/Wrappers/RequestHandlerWrapper.cs
class RequestHandlerBase (line 9) | public abstract class RequestHandlerBase
method Handle (line 11) | public abstract Task<object?> Handle(object request, IServiceProvider ...
class RequestHandlerWrapper (line 15) | public abstract class RequestHandlerWrapper<TResponse> : RequestHandlerBase
method Handle (line 17) | public abstract Task<TResponse> Handle(IRequest<TResponse> request, IS...
method Handle (line 23) | public abstract Task<Unit> Handle(IRequest request, IServiceProvider s...
class RequestHandlerWrapper (line 21) | public abstract class RequestHandlerWrapper : RequestHandlerBase
method Handle (line 17) | public abstract Task<TResponse> Handle(IRequest<TResponse> request, IS...
method Handle (line 23) | public abstract Task<Unit> Handle(IRequest request, IServiceProvider s...
class RequestHandlerWrapperImpl (line 27) | public class RequestHandlerWrapperImpl<TRequest, TResponse> : RequestHan...
method Handle (line 30) | public override async Task<object?> Handle(object request, IServicePro...
method Handle (line 34) | public override Task<TResponse> Handle(IRequest<TResponse> request, IS...
method Handle (line 51) | public override async Task<object?> Handle(object request, IServicePro...
method Handle (line 55) | public override Task<Unit> Handle(IRequest request, IServiceProvider s...
class RequestHandlerWrapperImpl (line 48) | public class RequestHandlerWrapperImpl<TRequest> : RequestHandlerWrapper
method Handle (line 30) | public override async Task<object?> Handle(object request, IServicePro...
method Handle (line 34) | public override Task<TResponse> Handle(IRequest<TResponse> request, IS...
method Handle (line 51) | public override async Task<object?> Handle(object request, IServicePro...
method Handle (line 55) | public override Task<Unit> Handle(IRequest request, IServiceProvider s...
FILE: src/MediatR/Wrappers/StreamRequestHandlerWrapper.cs
class StreamRequestHandlerBase (line 12) | internal abstract class StreamRequestHandlerBase
method Handle (line 14) | public abstract IAsyncEnumerable<object?> Handle(object request, IServ...
class StreamRequestHandlerWrapper (line 17) | internal abstract class StreamRequestHandlerWrapper<TResponse> : StreamR...
method Handle (line 19) | public abstract IAsyncEnumerable<TResponse> Handle(
class StreamRequestHandlerWrapperImpl (line 25) | internal class StreamRequestHandlerWrapperImpl<TRequest, TResponse>
method Handle (line 29) | public override async IAsyncEnumerable<object?> Handle(object request,...
method Handle (line 37) | public override async IAsyncEnumerable<TResponse> Handle(IStreamReques...
method NextWrapper (line 64) | private static async IAsyncEnumerable<T> NextWrapper<T>(
FILE: test/MediatR.Benchmarks/Benchmarks.cs
class Benchmarks (line 8) | [DotTraceDiagnoser]
method GlobalSetup (line 15) | [GlobalSetup]
method SendingRequests (line 33) | [Benchmark]
method PublishingNotifications (line 39) | [Benchmark]
FILE: test/MediatR.Benchmarks/DotTraceDiagnoser.cs
class DotTraceDiagnoserAttribute (line 18) | internal sealed class DotTraceDiagnoserAttribute : Attribute, IConfigSource
method DotTraceDiagnoserAttribute (line 20) | public DotTraceDiagnoserAttribute()
class DotTraceDiagnoser (line 30) | internal sealed class DotTraceDiagnoser : IDiagnoser
method DotTraceDiagnoser (line 37) | public DotTraceDiagnoser()
method GetRunMode (line 43) | public RunMode GetRunMode(BenchmarkCase benchmarkCase) => RunMode.Extr...
method Handle (line 46) | public void Handle(HostSignal signal, DiagnoserActionParameters parame...
method RunDotTrace (line 72) | private void RunDotTrace(DiagnoserActionParameters parameters)
method PrepareProcessStartInfo (line 86) | private ProcessStartInfo PrepareProcessStartInfo(DiagnoserActionParame...
method ProcessResults (line 101) | public IEnumerable<Metric> ProcessResults(DiagnoserResults results) =>...
method DisplayResults (line 104) | public void DisplayResults(ILogger logger) { }
method Validate (line 107) | public IEnumerable<ValidationError> Validate(ValidationParameters vali...
method CanRunDotTrace (line 118) | private static bool CanRunDotTrace()
FILE: test/MediatR.Benchmarks/GenericPipelineBehavior.cs
class GenericPipelineBehavior (line 7) | public class GenericPipelineBehavior<TRequest, TResponse> : IPipelineBeh...
method GenericPipelineBehavior (line 12) | public GenericPipelineBehavior(TextWriter writer)
method Handle (line 17) | public async Task<TResponse> Handle(TRequest request, RequestHandlerDe...
FILE: test/MediatR.Benchmarks/GenericRequestPostProcessor.cs
class GenericRequestPostProcessor (line 8) | public class GenericRequestPostProcessor<TRequest, TResponse> : IRequest...
method GenericRequestPostProcessor (line 13) | public GenericRequestPostProcessor(TextWriter writer)
method Process (line 18) | public Task Process(TRequest request, TResponse response, Cancellation...
FILE: test/MediatR.Benchmarks/GenericRequestPreProcessor.cs
class GenericRequestPreProcessor (line 8) | public class GenericRequestPreProcessor<TRequest> : IRequestPreProcessor...
method GenericRequestPreProcessor (line 13) | public GenericRequestPreProcessor(TextWriter writer)
method Process (line 18) | public Task Process(TRequest request, CancellationToken cancellationTo...
FILE: test/MediatR.Benchmarks/Ping.cs
class Ping (line 6) | public class Ping : IRequest
class PingHandler (line 11) | public class PingHandler : IRequestHandler<Ping>
method Handle (line 13) | public Task Handle(Ping request, CancellationToken cancellationToken) ...
FILE: test/MediatR.Benchmarks/Pinged.cs
class Pinged (line 6) | public class Pinged : INotification
class PingedHandler (line 10) | public class PingedHandler : INotificationHandler<Pinged>
method Handle (line 12) | public Task Handle(Pinged notification, CancellationToken cancellation...
FILE: test/MediatR.Benchmarks/Program.cs
class Program (line 5) | public class Program
method Main (line 7) | public static void Main(string[] args) => BenchmarkSwitcher.FromAssemb...
FILE: test/MediatR.DependencyInjectionTests/Abstractions/BaseAssemblyResolutionTests.cs
class BaseAssemblyResolutionTests (line 7) | public abstract class BaseAssemblyResolutionTests(BaseServiceProviderFix...
method Should_Resolve_Mediator (line 11) | [Fact]
method Should_Resolve_Public_RequestHandler (line 16) | [Fact]
method Should_Resolve_Internal_RequestHandler (line 21) | [Fact]
method Should_Resolve_Private_RequestHandler (line 26) | [Fact]
method Should_Resolve_Public_Void_RequestHandler (line 31) | [Fact]
method Should_Resolve_Internal_Void_RequestHandler (line 36) | [Fact]
method Should_Resolve_Private_Void_RequestHandler (line 41) | [Fact]
method Should_Resolve_Public_Private_Internal_Notification_Handlers (line 46) | [Fact]
method Should_Resolve_Public_Stream_Request_Handlers (line 52) | [Fact]
method Should_Resolve_Internal_Stream_Request_Handlers (line 57) | [Fact]
method Should_Resolve_Private_Stream_Request_Handlers (line 62) | [Fact]
FILE: test/MediatR.DependencyInjectionTests/Abstractions/BaseServiceProviderFixture.cs
class BaseServiceProviderFixture (line 3) | public class BaseServiceProviderFixture
FILE: test/MediatR.DependencyInjectionTests/AutoFacDependencyInjectionTests.cs
class AutoFacDependencyInjectionTests (line 6) | public class AutoFacDependencyInjectionTests : BaseAssemblyResolutionTests
method AutoFacDependencyInjectionTests (line 8) | public AutoFacDependencyInjectionTests() : base(new AutoFacServiceProv...
FILE: test/MediatR.DependencyInjectionTests/Contracts/Notifications/Ding.cs
type Ding (line 3) | public record Ding : INotification
FILE: test/MediatR.DependencyInjectionTests/Contracts/Requests/InternalPing.cs
type InternalPing (line 3) | internal record InternalPing : IRequest<Pong>
FILE: test/MediatR.DependencyInjectionTests/Contracts/Requests/InternalVoidPing.cs
type InternalVoidPing (line 3) | internal record InternalVoidPing : IRequest
FILE: test/MediatR.DependencyInjectionTests/Contracts/Requests/PrivatePing.cs
type PrivatePing (line 3) | public record PrivatePing : IRequest<Pong>
FILE: test/MediatR.DependencyInjectionTests/Contracts/Requests/PrivateVoidPing.cs
type PrivateVoidPing (line 3) | public record PrivateVoidPing : IRequest
FILE: test/MediatR.DependencyInjectionTests/Contracts/Requests/PublicPing.cs
type PublicPing (line 3) | public record PublicPing : IRequest<Pong>
FILE: test/MediatR.DependencyInjectionTests/Contracts/Requests/PublicVoidPing.cs
type PublicVoidPing (line 3) | public record PublicVoidPing : IRequest
FILE: test/MediatR.DependencyInjectionTests/Contracts/Responses/Pong.cs
type Pong (line 3) | public record Pong;
type Zong (line 4) | public record Zong;
FILE: test/MediatR.DependencyInjectionTests/Contracts/StreamRequests/InternalZing.cs
type InternalZing (line 3) | internal record InternalZing : IStreamRequest<Zong>
FILE: test/MediatR.DependencyInjectionTests/Contracts/StreamRequests/PrivateZing.cs
type PrivateZing (line 3) | internal record PrivateZing : IStreamRequest<Zong>
FILE: test/MediatR.DependencyInjectionTests/Contracts/StreamRequests/PublicZing.cs
type PublicZing (line 3) | public record PublicZing : IStreamRequest<Zong>
FILE: test/MediatR.DependencyInjectionTests/MicrosoftDependencyInjectionTests.cs
class MicrosoftDependencyInjectionTests (line 6) | public class MicrosoftDependencyInjectionTests : BaseAssemblyResolutionT...
method MicrosoftDependencyInjectionTests (line 8) | public MicrosoftDependencyInjectionTests() : base(new MicrosoftService...
FILE: test/MediatR.DependencyInjectionTests/Providers/AutoFacServiceProviderFixture.cs
class AutoFacServiceProviderFixture (line 8) | public class AutoFacServiceProviderFixture : BaseServiceProviderFixture
FILE: test/MediatR.DependencyInjectionTests/Providers/DryIocServiceProviderFixture.cs
class DryIocServiceProviderFixture (line 8) | public class DryIocServiceProviderFixture : BaseServiceProviderFixture
FILE: test/MediatR.DependencyInjectionTests/Providers/LamarServiceProviderFixture.cs
class LamarServiceProviderFixture (line 7) | public class LamarServiceProviderFixture : BaseServiceProviderFixture
FILE: test/MediatR.DependencyInjectionTests/Providers/LightInjectServiceProviderFixture.cs
class LightInjectServiceProviderFixture (line 8) | public class LightInjectServiceProviderFixture : BaseServiceProviderFixture
FILE: test/MediatR.DependencyInjectionTests/Providers/MicrosoftServiceProviderFixture.cs
class MicrosoftServiceProviderFixture (line 6) | public class MicrosoftServiceProviderFixture : BaseServiceProviderFixture
FILE: test/MediatR.DependencyInjectionTests/Providers/StashBoxServiceProviderFixture.cs
class StashBoxServiceProviderFixture (line 7) | public class StashBoxServiceProviderFixture : BaseServiceProviderFixture
FILE: test/MediatR.DependencyInjectionTests/StashBoxDependencyInjectionTests.cs
class StashBoxDependencyInjectionTests (line 6) | public class StashBoxDependencyInjectionTests : BaseAssemblyResolutionTests
method StashBoxDependencyInjectionTests (line 8) | public StashBoxDependencyInjectionTests() : base(new StashBoxServicePr...
FILE: test/MediatR.Tests/CreateStreamTests.cs
class CreateStreamTests (line 12) | public class CreateStreamTests
class Ping (line 15) | public class Ping : IStreamRequest<Pong>
class Pong (line 20) | public class Pong
class PingStreamHandler (line 25) | public class PingStreamHandler : IStreamRequestHandler<Ping, Pong>
method Handle (line 27) | public async IAsyncEnumerable<Pong> Handle(Ping request, [Enumerator...
method Should_resolve_main_handler (line 33) | [Fact]
method Should_resolve_main_handler_via_dynamic_dispatch (line 63) | [Fact]
method Should_resolve_main_handler_by_specific_interface (line 94) | [Fact]
method Should_raise_execption_on_null_request (line 123) | [Fact]
method Should_raise_execption_on_null_request_via_dynamic_dispatch (line 136) | [Fact]
FILE: test/MediatR.Tests/ExceptionTests.cs
class ExceptionTests (line 10) | public class ExceptionTests
class Ping (line 14) | public class Ping : IRequest<Pong>
class Pong (line 18) | public class Pong
class VoidPing (line 22) | public class VoidPing : IRequest
class Pinged (line 26) | public class Pinged : INotification
class AsyncPing (line 30) | public class AsyncPing : IRequest<Pong>
class AsyncVoidPing (line 34) | public class AsyncVoidPing : IRequest
class AsyncPinged (line 38) | public class AsyncPinged : INotification
class NullPing (line 42) | public class NullPing : IRequest<Pong>
class VoidNullPing (line 46) | public class VoidNullPing : IRequest
class NullPinged (line 50) | public class NullPinged : INotification
class NullPingHandler (line 54) | public class NullPingHandler : IRequestHandler<NullPing, Pong>
method Handle (line 56) | public Task<Pong> Handle(NullPing request, CancellationToken cancell...
class VoidNullPingHandler (line 62) | public class VoidNullPingHandler : IRequestHandler<VoidNullPing>
method Handle (line 64) | public Task Handle(VoidNullPing request, CancellationToken cancellat...
method ExceptionTests (line 70) | public ExceptionTests()
method Should_throw_for_send (line 79) | [Fact]
method Should_throw_for_void_send (line 85) | [Fact]
method Should_not_throw_for_publish (line 91) | [Fact]
method Should_throw_for_async_send (line 106) | [Fact]
method Should_throw_for_async_void_send (line 112) | [Fact]
method Should_not_throw_for_async_publish (line 118) | [Fact]
method Should_throw_argument_exception_for_send_when_request_is_null (line 133) | [Fact]
method Should_throw_argument_exception_for_void_send_when_request_is_null (line 152) | [Fact]
method Should_throw_argument_exception_for_publish_when_request_is_null (line 171) | [Fact]
method Should_throw_argument_exception_for_publish_when_request_is_null_object (line 190) | [Fact]
method Should_throw_argument_exception_for_publish_when_request_is_not_notification (line 209) | [Fact]
class PingException (line 228) | public class PingException : IRequest
class PingExceptionHandler (line 233) | public class PingExceptionHandler : IRequestHandler<PingException>
method Handle (line 235) | public Task Handle(PingException request, CancellationToken cancella...
method Should_throw_exception_for_non_generic_send_when_exception_occurs (line 241) | [Fact]
method Should_throw_exception_for_non_request_send (line 261) | [Fact]
class NonRequest (line 281) | public class NonRequest
method Should_throw_exception_for_generic_send_when_exception_occurs (line 286) | [Fact]
FILE: test/MediatR.Tests/GenericRequestHandlerTests.cs
class GenericRequestHandlerTests (line 6) | [Collection(nameof(ServiceFactoryCollectionBehavior))]
method ShouldResolveAllCombinationsOfGenericHandler (line 10) | [Theory]
method ShouldRegisterTheCorrectAmountOfHandlers (line 49) | [Theory]
method ShouldNotRegisterDuplicateHandlers (line 65) | [Theory]
method ShouldThrowExceptionWhenTypesClosingExceedsMaximum (line 86) | [Fact]
method ShouldThrowExceptionWhenGenericHandlerRegistrationsExceedsMaximum (line 105) | [Fact]
method ShouldThrowExceptionWhenGenericTypeParametersExceedsMaximum (line 124) | [Fact]
method ShouldThrowExceptionWhenTimeoutOccurs (line 143) | [Fact]
method ShouldNotRegisterGenericHandlersWhenOptingOut (line 166) | [Fact]
FILE: test/MediatR.Tests/GenericTypeConstraintsTests.cs
class GenericTypeConstraintsTests (line 12) | public class GenericTypeConstraintsTests
type IGenericTypeRequestHandlerTestClass (line 14) | public interface IGenericTypeRequestHandlerTestClass<TRequest> where T...
method Handle (line 16) | Type[] Handle(TRequest request);
class GenericTypeRequestHandlerTestClass (line 19) | public abstract class GenericTypeRequestHandlerTestClass<TRequest> : I...
method GenericTypeRequestHandlerTestClass (line 29) | public GenericTypeRequestHandlerTestClass()
method Handle (line 39) | public Type[] Handle(TRequest request)
class GenericTypeConstraintPing (line 45) | public class GenericTypeConstraintPing : GenericTypeRequestHandlerTest...
class GenericTypeConstraintJing (line 50) | public class GenericTypeConstraintJing : GenericTypeRequestHandlerTest...
class Jing (line 55) | public class Jing : IRequest
class JingHandler (line 60) | public class JingHandler : IRequestHandler<Jing>
method Handle (line 62) | public Task Handle(Jing request, CancellationToken cancellationToken)
class Ping (line 69) | public class Ping : IRequest<Pong>
class Pong (line 74) | public class Pong
class PingHandler (line 79) | public class PingHandler : IRequestHandler<Ping, Pong>
method Handle (line 81) | public Task<Pong> Handle(Ping request, CancellationToken cancellatio...
method GenericTypeConstraintsTests (line 89) | public GenericTypeConstraintsTests()
method Should_Resolve_Void_Return_Request (line 105) | [Fact]
method Should_Resolve_Response_Return_Request (line 132) | [Fact]
FILE: test/MediatR.Tests/Licensing/LicenseValidatorTests.cs
class LicenseValidatorTests (line 12) | public class LicenseValidatorTests
method Should_return_invalid_when_no_claims (line 14) | [Fact]
method Should_return_valid_when_community (line 35) | [Fact]
method Should_return_invalid_when_not_correct_type (line 63) | [Fact]
method Should_return_invalid_when_expired (line 90) | [Fact]
method Should_allow_perpetual_license_when_build_date_before_expiration (line 117) | [Fact]
method Should_reject_perpetual_license_when_build_date_after_expiration (line 147) | [Fact]
method Should_handle_missing_perpetual_claim (line 176) | [Fact]
method Should_fall_back_to_expiration_error_when_perpetual_and_build_date_is_null (line 204) | [Fact]
method Should_return_valid_for_actual_valid_license (line 233) | [Fact(Skip = "Needs license")]
method Should_return_valid_for_actual_valid_license_via_static_property (line 260) | [Fact(Skip = "Needs license")]
FILE: test/MediatR.Tests/MicrosoftExtensionsDI/AssemblyResolutionTests.cs
class AssemblyResolutionTests (line 12) | public class AssemblyResolutionTests
method AssemblyResolutionTests (line 16) | public AssemblyResolutionTests()
method ShouldResolveMediator (line 29) | [Fact]
method ShouldResolveRequestHandler (line 35) | [Fact]
method ShouldResolveInternalHandler (line 41) | [Fact]
method ShouldResolveNotificationHandlers (line 47) | [Fact]
method ShouldResolveStreamHandlers (line 53) | [Fact]
method ShouldRequireAtLeastOneAssembly (line 59) | [Fact]
method ShouldResolveGenericVoidRequestHandler (line 69) | [Fact]
method ShouldResolveGenericReturnTypeRequestHandler (line 75) | [Fact]
method ShouldResolveGenericPingRequestHandler (line 81) | [Fact]
method ShouldResolveVoidGenericPingRequestHandler (line 87) | [Fact]
method ShouldNotThrowWhenAssemblyThrowsReflectionTypeLoadException (line 93) | [Fact]
class BrokenAssembly (line 111) | private class BrokenAssembly : Assembly
FILE: test/MediatR.Tests/MicrosoftExtensionsDI/BaseGenericRequestHandlerTests.cs
class BaseGenericRequestHandlerTests (line 11) | public abstract class BaseGenericRequestHandlerTests
method GenerateTypesClosingExceedsMaximumAssembly (line 13) | protected static Assembly GenerateTypesClosingExceedsMaximumAssembly() =>
method GenerateHandlerRegistrationsExceedsMaximumAssembly (line 16) | protected static Assembly GenerateHandlerRegistrationsExceedsMaximumAs...
method GenerateGenericTypeParametersExceedsMaximumAssembly (line 19) | protected static Assembly GenerateGenericTypeParametersExceedsMaximumA...
method GenerateTimeoutOccursAssembly (line 22) | protected static Assembly GenerateTimeoutOccursAssembly() =>
method GenerateOptOutAssembly (line 25) | protected static Assembly GenerateOptOutAssembly() =>
method CreateHandlerForOptOutTest (line 28) | protected static void CreateHandlerForOptOutTest(ModuleBuilder moduleB...
method CreateHandlerForMissingConstraintsTest (line 31) | protected static void CreateHandlerForMissingConstraintsTest(ModuleBui...
method CreateHandlerForExceedsMaximumClassesTest (line 34) | protected static void CreateHandlerForExceedsMaximumClassesTest(Module...
method CreateHandlerForExceedsMaximumHandlerRegistrationsTest (line 37) | protected static void CreateHandlerForExceedsMaximumHandlerRegistratio...
method CreateHandlerForExceedsMaximumGenericTypeParametersTest (line 40) | protected static void CreateHandlerForExceedsMaximumGenericTypeParamet...
method CreateHandlerForTimeoutOccursTest (line 43) | protected static void CreateHandlerForTimeoutOccursTest(ModuleBuilder ...
method CreateHandlerForCombinationsTest (line 46) | protected static void CreateHandlerForCombinationsTest(ModuleBuilder m...
method CreateClass (line 49) | protected static void CreateClass(ModuleBuilder moduleBuilder, string ...
method CreateInterface (line 56) | protected static Type CreateInterface(ModuleBuilder moduleBuilder, str...
method CreateAssemblyModuleBuilder (line 62) | protected static AssemblyBuilder CreateAssemblyModuleBuilder(string na...
method GenerateCombinationsTestAssembly (line 74) | protected static AssemblyBuilder GenerateCombinationsTestAssembly(int ...
method GetGenericParameterNames (line 86) | protected static string[] GetGenericParameterNames(int numberOfTypePar...
method CreateRequestHandler (line 89) | protected static void CreateRequestHandler(ModuleBuilder moduleBuilder...
method CreateTestClassesAndInterfaces (line 139) | protected static void CreateTestClassesAndInterfaces(ModuleBuilder mod...
method GenerateCombinations (line 157) | protected List<Type[]> GenerateCombinations(Type[] types, int interfaces)
method GenerateCombinationsRecursive (line 168) | protected List<Type[]> GenerateCombinationsRecursive(List<Type>[] grou...
method CalculateTotalCombinations (line 189) | protected static int CalculateTotalCombinations(int numberOfClasses, i...
FILE: test/MediatR.Tests/MicrosoftExtensionsDI/CustomMediatorTests.cs
class CustomMediatorTests (line 10) | public class CustomMediatorTests
method CustomMediatorTests (line 14) | public CustomMediatorTests()
method ShouldResolveMediator (line 27) | [Fact]
method ShouldResolveRequestHandler (line 34) | [Fact]
method ShouldResolveNotificationHandlers (line 40) | [Fact]
method Can_Call_AddMediatr_multiple_times (line 46) | [Fact]
FILE: test/MediatR.Tests/MicrosoftExtensionsDI/DerivingRequestsTests.cs
class DerivingRequestsTests (line 9) | public class DerivingRequestsTests
method DerivingRequestsTests (line 14) | public DerivingRequestsTests()
method ShouldReturnPingPong (line 24) | [Fact]
method ShouldReturnDerivedPingPong (line 31) | [Fact]
FILE: test/MediatR.Tests/MicrosoftExtensionsDI/DuplicateAssemblyResolutionTests.cs
class DuplicateAssemblyResolutionTests (line 10) | public class DuplicateAssemblyResolutionTests
method DuplicateAssemblyResolutionTests (line 14) | public DuplicateAssemblyResolutionTests()
method ShouldResolveNotificationHandlersOnlyOnce (line 22) | [Fact]
FILE: test/MediatR.Tests/MicrosoftExtensionsDI/Handlers.cs
class Ping (line 10) | public class Ping : IRequest<Pong>
class DerivedPing (line 16) | public class DerivedPing : Ping
class Pong (line 20) | public class Pong
class Zing (line 25) | public class Zing : IRequest<Zong>
class Zong (line 30) | public class Zong
class Ding (line 35) | public class Ding : IRequest
class Pinged (line 40) | public class Pinged : INotification
class InternalPing (line 45) | class InternalPing : IRequest { }
class StreamPing (line 47) | public class StreamPing : IStreamRequest<Pong>
class GenericHandler (line 52) | public class GenericHandler : INotificationHandler<INotification>
method Handle (line 54) | public Task Handle(INotification notification, CancellationToken cance...
class DingAsyncHandler (line 60) | public class DingAsyncHandler : IRequestHandler<Ding>
method Handle (line 62) | public Task Handle(Ding message, CancellationToken cancellationToken) ...
class PingedHandler (line 65) | public class PingedHandler : INotificationHandler<Pinged>
method Handle (line 67) | public Task Handle(Pinged notification, CancellationToken cancellation...
class PingedAlsoHandler (line 73) | public class PingedAlsoHandler : INotificationHandler<Pinged>
method Handle (line 75) | public Task Handle(Pinged notification, CancellationToken cancellation...
class PingedAlsoOpenHandler (line 81) | public class PingedAlsoOpenHandler<TNotification> : INotificationHandler...
method Handle (line 84) | public Task Handle(TNotification notification, CancellationToken cance...
class Logger (line 87) | public class Logger
class PingHandler (line 92) | public class PingHandler : IRequestHandler<Ping, Pong>
method PingHandler (line 96) | public PingHandler(Logger logger)
method Handle (line 100) | public Task<Pong> Handle(Ping message, CancellationToken cancellationT...
class DerivedPingHandler (line 110) | public class DerivedPingHandler : IRequestHandler<DerivedPing, Pong>
method DerivedPingHandler (line 114) | public DerivedPingHandler(Logger logger)
method Handle (line 118) | public Task<Pong> Handle(DerivedPing message, CancellationToken cancel...
class ZingHandler (line 125) | public class ZingHandler : IRequestHandler<Zing, Zong>
method ZingHandler (line 129) | public ZingHandler(Logger output)
method Handle (line 133) | public Task<Zong> Handle(Zing message, CancellationToken cancellationT...
class PingStreamHandler (line 140) | public class PingStreamHandler : IStreamRequestHandler<StreamPing, Pong>
method PingStreamHandler (line 144) | public PingStreamHandler(Logger output)
method Handle (line 148) | public async IAsyncEnumerable<Pong> Handle(StreamPing request, [Enumer...
class DuplicateTest (line 156) | public class DuplicateTest : IRequest<string> { }
class DuplicateHandler1 (line 157) | public class DuplicateHandler1 : IRequestHandler<DuplicateTest, string>
method Handle (line 159) | public Task<string> Handle(DuplicateTest message, CancellationToken ca...
class DuplicateHandler2 (line 165) | public class DuplicateHandler2 : IRequestHandler<DuplicateTest, string>
method Handle (line 167) | public Task<string> Handle(DuplicateTest message, CancellationToken ca...
class InternalPingHandler (line 173) | class InternalPingHandler : IRequestHandler<InternalPing>
method Handle (line 175) | public Task Handle(InternalPing request, CancellationToken cancellatio...
class MyCustomMediator (line 178) | class MyCustomMediator : IMediator
method Send (line 180) | public Task<object?> Send(object request, CancellationToken cancellati...
method CreateStream (line 185) | public IAsyncEnumerable<TResponse> CreateStream<TResponse>(IStreamRequ...
method CreateStream (line 191) | public IAsyncEnumerable<object?> CreateStream(object request, Cancella...
method Publish (line 196) | public Task Publish(object notification, CancellationToken cancellatio...
method Publish (line 201) | public Task Publish<TNotification>(TNotification notification, Cancell...
method Send (line 206) | public Task<TResponse> Send<TResponse>(IRequest<TResponse> request, Ca...
method Send (line 210) | public Task Send<TRequest>(TRequest request, CancellationToken cancell...
type ITypeArgument (line 217) | interface ITypeArgument { }
class ConcreteTypeArgument (line 218) | class ConcreteTypeArgument : ITypeArgument { }
class OpenGenericVoidRequest (line 219) | class OpenGenericVoidRequest<T> : IRequest
class OpenGenericVoidRequestHandler (line 222) | class OpenGenericVoidRequestHandler<T> : IRequestHandler<OpenGenericVoid...
method Handle (line 225) | public Task Handle(OpenGenericVoidRequest<T> request, CancellationToke...
class OpenGenericReturnTypeRequest (line 227) | class OpenGenericReturnTypeRequest<T> : IRequest<string>
class OpenGenericReturnTypeRequestHandler (line 230) | class OpenGenericReturnTypeRequestHandler<T> : IRequestHandler<OpenGener...
method Handle (line 233) | public Task<string> Handle(OpenGenericReturnTypeRequest<T> request, Ca...
class GenericPing (line 236) | public class GenericPing<T> : IRequest<T>
class GenericPingHandler (line 242) | public class GenericPingHandler<T> : IRequestHandler<GenericPing<T>, T>
method Handle (line 245) | public Task<T> Handle(GenericPing<T> request, CancellationToken cancel...
class VoidGenericPing (line 248) | public class VoidGenericPing<T> : IRequest
class VoidGenericPingHandler (line 252) | public class VoidGenericPingHandler<T> : IRequestHandler<VoidGenericPing...
method Handle (line 255) | public Task Handle(VoidGenericPing<T> request, CancellationToken cance...
class Foo (line 265) | public class Foo : IRequest<Bar>
class Bar (line 271) | public class Bar
class FooHandler (line 276) | public class FooHandler : IRequestHandler<Foo, Bar>
method FooHandler (line 280) | public FooHandler(Logger logger)
method Handle (line 284) | public Task<Bar> Handle(Foo message, CancellationToken cancellationToken)
FILE: test/MediatR.Tests/MicrosoftExtensionsDI/Issue1118Tests.cs
class Issue1118Tests (line 19) | public class Issue1118Tests
class CallLog (line 21) | public class CallLog
class BaseEvent (line 26) | public class BaseEvent : INotification { }
class DerivedEvent (line 28) | public class DerivedEvent : BaseEvent { }
class BaseEventHandler (line 33) | public class BaseEventHandler : INotificationHandler<BaseEvent>
method BaseEventHandler (line 37) | public BaseEventHandler(IServiceProvider serviceProvider)
method Handle (line 40) | public Task Handle(BaseEvent notification, CancellationToken cancell...
class DerivedEventHandler (line 47) | public class DerivedEventHandler : INotificationHandler<DerivedEvent>
method DerivedEventHandler (line 51) | public DerivedEventHandler(IServiceProvider serviceProvider)
method Handle (line 54) | public Task Handle(DerivedEvent notification, CancellationToken canc...
method BuildProvider (line 61) | private static IServiceProvider BuildProvider()
method Publishing_BaseEvent_Should_Call_BaseEventHandler_Once (line 70) | [Fact]
method Publishing_DerivedEvent_Should_Call_BaseEventHandler_ExactlyOnce (line 81) | [Fact]
method Publishing_DerivedEvent_Should_Call_DerivedEventHandler_Once (line 93) | [Fact]
FILE: test/MediatR.Tests/MicrosoftExtensionsDI/NotificationPublisherTests.cs
class NotificationPublisherTests (line 13) | public class NotificationPublisherTests
class MockPublisher (line 15) | public class MockPublisher : INotificationPublisher
method Publish (line 19) | public async Task Publish(IEnumerable<NotificationHandlerExecutor> h...
method ShouldResolveDefaultPublisher (line 29) | [Fact]
method ShouldSubstitutePublisherInstance (line 50) | [Fact]
method ShouldSubstitutePublisherServiceType (line 72) | [Fact]
method ShouldSubstitutePublisherServiceTypeWithWhenAll (line 98) | [Fact]
FILE: test/MediatR.Tests/MicrosoftExtensionsDI/PipeLineMultiCallToConstructorTest.cs
class PipelineMultiCallToConstructorTests (line 11) | public class PipelineMultiCallToConstructorTests
class ConstructorTestBehavior (line 13) | public class ConstructorTestBehavior<TRequest, TResponse> : IPipelineB...
method ConstructorTestBehavior (line 18) | public ConstructorTestBehavior(Logger output) => _output = output;
method Handle (line 20) | public async Task<TResponse> Handle(TRequest request, RequestHandler...
class ConstructorTestRequest (line 30) | public class ConstructorTestRequest : IRequest<ConstructorTestResponse>
class ConstructorTestResponse (line 35) | public class ConstructorTestResponse
class ConstructorTestHandler (line 40) | public class ConstructorTestHandler : IRequestHandler<ConstructorTestR...
method ResetCallCount (line 49) | public static void ResetCallCount()
method ConstructorTestHandler (line 57) | public ConstructorTestHandler(Logger logger)
method Handle (line 66) | public Task<ConstructorTestResponse> Handle(ConstructorTestRequest r...
method Should_not_call_constructor_multiple_times_when_using_a_pipeline (line 73) | [Fact]
FILE: test/MediatR.Tests/MicrosoftExtensionsDI/PipelineTests.cs
class PipelineTests (line 14) | public class PipelineTests
class OuterBehavior (line 16) | public class OuterBehavior : IPipelineBehavior<Ping, Pong>
method OuterBehavior (line 20) | public OuterBehavior(Logger output)
method Handle (line 25) | public async Task<Pong> Handle(Ping request, RequestHandlerDelegate<...
method OuterBehavior (line 119) | public OuterBehavior(Logger output)
method Handle (line 124) | public async Task<TResponse> Handle(TRequest request, RequestHandler...
class InnerBehavior (line 35) | public class InnerBehavior : IPipelineBehavior<Ping, Pong>
method InnerBehavior (line 39) | public InnerBehavior(Logger output)
method Handle (line 44) | public async Task<Pong> Handle(Ping request, RequestHandlerDelegate<...
method InnerBehavior (line 99) | public InnerBehavior(Logger output)
method Handle (line 104) | public async Task<TResponse> Handle(TRequest request, RequestHandler...
class OuterStreamBehavior (line 54) | public class OuterStreamBehavior : IStreamPipelineBehavior<Ping, Pong>
method OuterStreamBehavior (line 58) | public OuterStreamBehavior(Logger output)
method Handle (line 63) | public async IAsyncEnumerable<Pong> Handle(Ping request, StreamHandl...
class InnerStreamBehavior (line 74) | public class InnerStreamBehavior : IStreamPipelineBehavior<Ping, Pong>
method InnerStreamBehavior (line 78) | public InnerStreamBehavior(Logger output)
method Handle (line 83) | public async IAsyncEnumerable<Pong> Handle(Ping request, StreamHandl...
class InnerBehavior (line 94) | public class InnerBehavior<TRequest, TResponse> : IPipelineBehavior<TR...
method InnerBehavior (line 39) | public InnerBehavior(Logger output)
method Handle (line 44) | public async Task<Pong> Handle(Ping request, RequestHandlerDelegate<...
method InnerBehavior (line 99) | public InnerBehavior(Logger output)
method Handle (line 104) | public async Task<TResponse> Handle(TRequest request, RequestHandler...
class OuterBehavior (line 114) | public class OuterBehavior<TRequest, TResponse> : IPipelineBehavior<TR...
method OuterBehavior (line 20) | public OuterBehavior(Logger output)
method Handle (line 25) | public async Task<Pong> Handle(Ping request, RequestHandlerDelegate<...
method OuterBehavior (line 119) | public OuterBehavior(Logger output)
method Handle (line 124) | public async Task<TResponse> Handle(TRequest request, RequestHandler...
class ConstrainedBehavior (line 134) | public class ConstrainedBehavior<TRequest, TResponse> : IPipelineBehav...
method ConstrainedBehavior (line 140) | public ConstrainedBehavior(Logger output)
method Handle (line 145) | public async Task<TResponse> Handle(TRequest request, RequestHandler...
class FirstPreProcessor (line 155) | public class FirstPreProcessor<TRequest> : IRequestPreProcessor<TReque...
method FirstPreProcessor (line 159) | public FirstPreProcessor(Logger output)
method Process (line 163) | public Task Process(TRequest request, CancellationToken cancellation...
class FirstConcretePreProcessor (line 170) | public class FirstConcretePreProcessor : IRequestPreProcessor<Ping>
method FirstConcretePreProcessor (line 174) | public FirstConcretePreProcessor(Logger output)
method Process (line 178) | public Task Process(Ping request, CancellationToken cancellationToken)
class NextPreProcessor (line 185) | public class NextPreProcessor<TRequest> : IRequestPreProcessor<TReques...
method NextPreProcessor (line 189) | public NextPreProcessor(Logger output)
method Process (line 193) | public Task Process(TRequest request, CancellationToken cancellation...
class NextConcretePreProcessor (line 200) | public class NextConcretePreProcessor : IRequestPreProcessor<Ping>
method NextConcretePreProcessor (line 204) | public NextConcretePreProcessor(Logger output)
method Process (line 208) | public Task Process(Ping request, CancellationToken cancellationToken)
class FirstPostProcessor (line 215) | public class FirstPostProcessor<TRequest, TResponse> : IRequestPostPro...
method FirstPostProcessor (line 220) | public FirstPostProcessor(Logger output)
method Process (line 224) | public Task Process(TRequest request, TResponse response, Cancellati...
class FirstConcretePostProcessor (line 231) | public class FirstConcretePostProcessor : IRequestPostProcessor<Ping, ...
method FirstConcretePostProcessor (line 235) | public FirstConcretePostProcessor(Logger output)
method Process (line 239) | public Task Process(Ping request, Pong response, CancellationToken c...
class NextPostProcessor (line 246) | public class NextPostProcessor<TRequest, TResponse> : IRequestPostProc...
method NextPostProcessor (line 251) | public NextPostProcessor(Logger output)
method Process (line 255) | public Task Process(TRequest request, TResponse response, Cancellati...
class NextConcretePostProcessor (line 262) | public class NextConcretePostProcessor : IRequestPostProcessor<Ping, P...
method NextConcretePostProcessor (line 266) | public NextConcretePostProcessor(Logger output)
method Process (line 270) | public Task Process(Ping request, Pong response, CancellationToken c...
class PingPongGenericExceptionAction (line 277) | public class PingPongGenericExceptionAction : IRequestExceptionAction<...
method PingPongGenericExceptionAction (line 281) | public PingPongGenericExceptionAction(Logger output) => _output = ou...
method Execute (line 283) | public Task Execute(Ping request, Exception exception, CancellationT...
class PingPongApplicationExceptionAction (line 291) | public class PingPongApplicationExceptionAction : IRequestExceptionAct...
method PingPongApplicationExceptionAction (line 295) | public PingPongApplicationExceptionAction(Logger output) => _output ...
method Execute (line 297) | public Task Execute(Ping request, ApplicationException exception, Ca...
class PingPongExceptionActionForType1 (line 305) | public class PingPongExceptionActionForType1 : IRequestExceptionAction...
method PingPongExceptionActionForType1 (line 309) | public PingPongExceptionActionForType1(Logger output) => _output = o...
method Execute (line 311) | public Task Execute(Ping request, SystemException exception, Cancell...
class PingPongExceptionActionForType2 (line 319) | public class PingPongExceptionActionForType2 : IRequestExceptionAction...
method PingPongExceptionActionForType2 (line 323) | public PingPongExceptionActionForType2(Logger output) => _output = o...
method Execute (line 325) | public Task Execute(Ping request, SystemException exception, Cancell...
class PingPongExceptionHandlerForType (line 333) | public class PingPongExceptionHandlerForType : IRequestExceptionHandle...
method Handle (line 335) | public Task Handle(Ping request, ApplicationException exception, Req...
class PingPongGenericExceptionHandler (line 343) | public class PingPongGenericExceptionHandler : IRequestExceptionHandle...
method PingPongGenericExceptionHandler (line 347) | public PingPongGenericExceptionHandler(Logger output) => _output = o...
method Handle (line 349) | public Task Handle(Ping request, Exception exception, RequestExcepti...
class NotAnOpenBehavior (line 357) | public class NotAnOpenBehavior : IPipelineBehavior<Ping, Pong>
method Handle (line 359) | public Task<Pong> Handle(Ping request, RequestHandlerDelegate<Pong> ...
class ThrowingBehavior (line 362) | public class ThrowingBehavior : IPipelineBehavior<Ping, Pong>
method Handle (line 364) | public Task<Pong> Handle(Ping request, RequestHandlerDelegate<Pong> ...
class NotAnOpenStreamBehavior (line 367) | public class NotAnOpenStreamBehavior : IStreamPipelineBehavior<Ping, P...
method Handle (line 369) | public IAsyncEnumerable<Pong> Handle(Ping request, StreamHandlerDele...
class OpenBehavior (line 372) | public class OpenBehavior<TRequest, TResponse> : IPipelineBehavior<TRe...
method Handle (line 375) | public Task<TResponse> Handle(TRequest request, RequestHandlerDelega...
class OpenStreamBehavior (line 378) | public class OpenStreamBehavior<TRequest, TResponse> : IStreamPipeline...
method Handle (line 381) | public IAsyncEnumerable<TResponse> Handle(TRequest request, StreamHa...
class MultiOpenBehavior (line 384) | public class MultiOpenBehavior<TRequest, TResponse> : IPipelineBehavio...
method Handle (line 387) | public Task<TResponse> Handle(TRequest request, RequestHandlerDelega...
method Handle (line 389) | public IAsyncEnumerable<TResponse> Handle(TRequest request, StreamHa...
method Should_wrap_with_behavior (line 392) | [Fact]
method Should_wrap_generics_with_behavior (line 423) | [Fact]
method Should_register_pre_and_post_processors (line 458) | [Fact]
method Should_pick_up_specific_exception_behaviors (line 499) | [Fact]
method Should_pick_up_base_exception_behaviors (line 517) | [Fact]
method Should_handle_exceptions_from_behaviors (line 535) | [Fact]
method Should_pick_up_exception_actions (line 557) | [Fact]
method Should_handle_constrained_generics (line 575) | [Fact]
method Should_throw_when_adding_non_open_behavior (line 644) | [Fact]
method Should_throw_when_adding_non_open_stream_behavior (line 650) | [Fact]
method Should_throw_when_adding_random_generic_type_as_open_behavior (line 656) | [Fact]
method Should_handle_open_behavior_registration (line 662) | [Fact]
method Should_handle_inferred_behavior_registration (line 695) | [Fact]
method Should_handle_inferred_stream_behavior_registration (line 727) | [Fact]
method Should_handle_inferred_pre_processor_registration (line 758) | [Fact]
method Should_handle_inferred_post_processor_registration (line 789) | [Fact]
method Should_handle_open_behaviors_registration_from_a_single_type (line 820) | [Fact]
method Should_auto_register_processors_when_configured_including_all_concrete_types (line 853) | [Fact]
type FooRequest (line 883) | public sealed record FooRequest : IRequest;
type IBlogger (line 885) | public interface IBlogger<T>
class Blogger (line 890) | public class Blogger<T> : IBlogger<T>
method Blogger (line 894) | public Blogger(Logger logger)
class FooRequestHandler (line 902) | public sealed class FooRequestHandler : IRequestHandler<FooRequest> {
method FooRequestHandler (line 903) | public FooRequestHandler(IBlogger<FooRequestHandler> logger)
method Handle (line 910) | public Task Handle(FooRequest request, CancellationToken cancellatio...
class ClosedBehavior (line 916) | sealed class ClosedBehavior : IPipelineBehavior<FooRequest, Unit> {
method ClosedBehavior (line 917) | public ClosedBehavior(IBlogger<ClosedBehavior> logger)
method Handle (line 924) | public Task<Unit> Handle(FooRequest request, RequestHandlerDelegate<...
class Open2Behavior (line 930) | sealed class Open2Behavior<TRequest, TResponse> : IPipelineBehavior<TR...
method Open2Behavior (line 932) | public Open2Behavior(IBlogger<Open2Behavior<TRequest, TResponse>> lo...
method Handle (line 938) | public Task<TResponse> Handle(TRequest request, RequestHandlerDelega...
method Should_register_correctly (line 943) | [Fact]
class OpenBehaviorMultipleRegistration0 (line 980) | sealed class OpenBehaviorMultipleRegistration0<TRequest, TResponse> : ...
method OpenBehaviorMultipleRegistration0 (line 983) | public OpenBehaviorMultipleRegistration0(IBlogger<OpenBehaviorMultip...
method Handle (line 990) | public Task<TResponse> Handle(TRequest request, RequestHandlerDelega...
class OpenBehaviorMultipleRegistration1 (line 996) | sealed class OpenBehaviorMultipleRegistration1<TRequest, TResponse> : ...
method OpenBehaviorMultipleRegistration1 (line 999) | public OpenBehaviorMultipleRegistration1(IBlogger<OpenBehaviorMultip...
method Handle (line 1006) | public Task<TResponse> Handle(TRequest request, RequestHandlerDelega...
class OpenBehaviorMultipleRegistration2 (line 1012) | sealed class OpenBehaviorMultipleRegistration2<TRequest, TResponse> : ...
method OpenBehaviorMultipleRegistration2 (line 1015) | public OpenBehaviorMultipleRegistration2(IBlogger<OpenBehaviorMultip...
method Handle (line 1022) | public Task<TResponse> Handle(TRequest request, RequestHandlerDelega...
method Should_register_open_behaviors_correctly (line 1030) | [Fact]
class ListPing (line 1072) | public class ListPing : IRequest<List<Pong>> { }
class ListPingHandler (line 1074) | public class ListPingHandler : IRequestHandler<ListPing, List<Pong>>
method ListPingHandler (line 1077) | public ListPingHandler(Logger output) => _output = output;
method Handle (line 1078) | public Task<List<Pong>> Handle(ListPing request, CancellationToken c...
class ListResponseBehavior (line 1085) | public class ListResponseBehavior<TRequest, TItem>
method ListResponseBehavior (line 1090) | public ListResponseBehavior(Logger output) => _output = output;
method Handle (line 1091) | public async Task<List<TItem>> Handle(TRequest request, RequestHandl...
method Should_apply_open_behavior_with_nested_generic_response_type (line 1100) | [Fact]
FILE: test/MediatR.Tests/MicrosoftExtensionsDI/StreamPipelineTests.cs
class StreamPipelineTests (line 16) | public class StreamPipelineTests
class OuterBehavior (line 18) | public class OuterBehavior : IStreamPipelineBehavior<StreamPing, Pong>
method OuterBehavior (line 22) | public OuterBehavior(Logger output)
method Handle (line 27) | public async IAsyncEnumerable<Pong> Handle(StreamPing request, Strea...
class InnerBehavior (line 38) | public class InnerBehavior : IStreamPipelineBehavior<StreamPing, Pong>
method InnerBehavior (line 42) | public InnerBehavior(Logger output)
method Handle (line 47) | public async IAsyncEnumerable<Pong> Handle(StreamPing request, Strea...
method Should_wrap_with_behavior (line 58) | [Fact]
method Should_register_and_wrap_with_behavior (line 89) | [Fact]
FILE: test/MediatR.Tests/MicrosoftExtensionsDI/TypeEvaluatorTests.cs
class TypeEvaluatorTests (line 12) | public class TypeEvaluatorTests
method TypeEvaluatorTests (line 18) | public TypeEvaluatorTests()
method ShouldResolveMediator (line 31) | [Fact]
method ShouldOnlyResolveIncludedRequestHandlers (line 37) | [Fact]
method ShouldNotRegisterUnNeededBehaviors (line 44) | [Fact]
FILE: test/MediatR.Tests/MicrosoftExtensionsDI/TypeResolutionTests.cs
class TypeResolutionTests (line 13) | public class TypeResolutionTests
method TypeResolutionTests (line 17) | public TypeResolutionTests()
method ShouldResolveMediator (line 26) | [Fact]
method ShouldResolveSender (line 32) | [Fact]
method ShouldResolvePublisher (line 38) | [Fact]
method ShouldResolveRequestHandler (line 44) | [Fact]
method ShouldResolveVoidRequestHandler (line 50) | [Fact]
method ShouldResolveNotificationHandlers (line 56) | [Fact]
method ShouldNotThrowWithMissingEnumerables (line 62) | [Fact]
method ShouldResolveFirstDuplicateHandler (line 68) | [Fact]
method ShouldResolveIgnoreSecondDuplicateHandler (line 76) | [Fact]
method ShouldHandleKeyedServices (line 82) | [Fact]
FILE: test/MediatR.Tests/NotificationHandlerTests.cs
class NotificationHandlerTests (line 9) | public class NotificationHandlerTests
class Ping (line 11) | public class Ping : INotification
class PongChildHandler (line 16) | public class PongChildHandler : NotificationHandler<Ping>
method PongChildHandler (line 20) | public PongChildHandler(TextWriter writer)
method Handle (line 25) | protected override void Handle(Ping notification)
method Should_call_abstract_handle_method (line 31) | [Fact]
FILE: test/MediatR.Tests/NotificationPublisherTests.cs
class NotificationPublisherTests (line 12) | public class NotificationPublisherTests
method NotificationPublisherTests (line 16) | public NotificationPublisherTests(ITestOutputHelper output) => _output...
class Notification (line 18) | public class Notification : INotification
class FirstHandler (line 22) | public class FirstHandler : INotificationHandler<Notification>
method Handle (line 24) | public async Task Handle(Notification notification, CancellationToke...
class SecondHandler (line 27) | public class SecondHandler : INotificationHandler<Notification>
method Handle (line 29) | public async Task Handle(Notification notification, CancellationToke...
method Should_handle_sequentially_by_default (line 33) | [Fact]
FILE: test/MediatR.Tests/Pipeline/RequestExceptionActionTests.cs
class RequestExceptionActionTests (line 5) | public class RequestExceptionActionTests
class Ping (line 7) | public class Ping : IRequest<Pong>
class Pong (line 12) | public class Pong
class PingPongException (line 17) | public abstract class PingPongException : Exception
method PingPongException (line 19) | protected PingPongException(string? message) : base(message + " Thro...
class PingException (line 24) | public class PingException : PingPongException
method PingException (line 26) | public PingException(string? message) : base(message)
class PongException (line 31) | public class PongException : PingPongException
method PongException (line 33) | public PongException(string message) : base(message)
class PingHandler (line 38) | public class PingHandler : IRequestHandler<Ping, Pong>
method Handle (line 40) | public Task<Pong> Handle(Ping request, CancellationToken cancellatio...
class GenericExceptionAction (line 46) | public class GenericExceptionAction<TRequest> : IRequestExceptionActio...
method Execute (line 50) | public Task Execute(TRequest request, Exception exception, Cancellat...
class PingPongExceptionAction (line 57) | public class PingPongExceptionAction<TRequest> : IRequestExceptionActi...
method Execute (line 61) | public Task Execute(TRequest request, PingPongException exception, C...
class PingExceptionAction (line 68) | public class PingExceptionAction : IRequestExceptionAction<Ping, PingE...
method Execute (line 72) | public Task Execute(Ping request, PingException exception, Cancellat...
class PongExceptionAction (line 79) | public class PongExceptionAction : IRequestExceptionAction<Ping, PongE...
method Execute (line 83) | public Task Execute(Ping request, PongException exception, Cancellat...
method Should_run_all_exception_actions_that_match_base_type (line 90) | [Fact]
method Should_run_matching_exception_actions_only_once (line 117) | [Fact]
FILE: test/MediatR.Tests/Pipeline/RequestExceptionHandlerTests.cs
class RequestExceptionHandlerTests (line 10) | public class RequestExceptionHandlerTests
class Ping (line 12) | public class Ping : IRequest<Pong>
class Pong (line 17) | public class Pong
class PingException (line 22) | public class PingException : Exception
method PingException (line 24) | public PingException(string? message) : base(message + " Thrown")
class PingHandler (line 29) | public class PingHandler : IRequestHandler<Ping, Pong>
method Handle (line 31) | public Task<Pong> Handle(Ping request, CancellationToken cancellatio...
class GenericPingExceptionHandler (line 37) | public class GenericPingExceptionHandler : IRequestExceptionHandler<Pi...
method Handle (line 41) | public Task Handle(Ping request, Exception exception, RequestExcepti...
class PingPongExceptionHandlerForType (line 48) | public class PingPongExceptionHandlerForType : IRequestExceptionHandle...
method Handle (line 50) | public Task Handle(Ping request, PingException exception, RequestExc...
class PingPongExceptionHandler (line 58) | public class PingPongExceptionHandler : IRequestExceptionHandler<Ping,...
method Handle (line 60) | public Task Handle(Ping request, Exception exception, RequestExcepti...
class PingPongExceptionHandlerNotHandled (line 68) | public class PingPongExceptionHandlerNotHandled : IRequestExceptionHan...
method Handle (line 70) | public Task Handle(Ping request, Exception exception, RequestExcepti...
class PingPongThrowingExceptionHandler (line 78) | public class PingPongThrowingExceptionHandler : IRequestExceptionHandl...
method Handle (line 80) | public Task Handle(Ping request, Exception exception, RequestExcepti...
method Should_run_exception_handler_and_allow_for_exception_not_to_throw (line 86) | [Fact]
method Should_run_exception_handler_and_allow_for_exception_to_be_still_thrown (line 105) | [Fact]
method Should_run_exception_handler_and_unwrap_expections_thrown_in_the_handler (line 127) | [Fact]
method Should_run_matching_exception_handlers_only_once (line 147) | [Fact]
FILE: test/MediatR.Tests/Pipeline/RequestPostProcessorTests.cs
class RequestPostProcessorTests (line 10) | public class RequestPostProcessorTests
class Ping (line 12) | public class Ping : IRequest<Pong>
class Pong (line 17) | public class Pong
class PingHandler (line 22) | public class PingHandler : IRequestHandler<Ping, Pong>
method Handle (line 24) | public Task<Pong> Handle(Ping request, CancellationToken cancellatio...
class PingPongPostProcessor (line 30) | public class PingPongPostProcessor : IRequestPostProcessor<Ping, Pong>
method Process (line 32) | public Task Process(Ping request, Pong response, CancellationToken c...
method Should_run_postprocessors (line 40) | [Fact]
FILE: test/MediatR.Tests/Pipeline/RequestPreProcessorTests.cs
class RequestPreProcessorTests (line 10) | public class RequestPreProcessorTests
class Ping (line 12) | public class Ping : IRequest<Pong>
class Pong (line 17) | public class Pong
class PingHandler (line 22) | public class PingHandler : IRequestHandler<Ping, Pong>
method Handle (line 24) | public Task<Pong> Handle(Ping request, CancellationToken cancellatio...
class PingPreProcessor (line 30) | public class PingPreProcessor : IRequestPreProcessor<Ping>
method Process (line 32) | public Task Process(Ping request, CancellationToken cancellationToken)
method Should_run_preprocessors (line 40) | [Fact]
FILE: test/MediatR.Tests/Pipeline/Streams/StreamPipelineBehaviorTests.cs
class StreamPipelineBehaviorTests (line 13) | public class StreamPipelineBehaviorTests
class Sing (line 15) | public class Sing : IStreamRequest<Song>
class Song (line 20) | public class Song
class SingHandler (line 25) | public class SingHandler : IStreamRequestHandler<Sing, Song>
method Handle (line 27) | public async IAsyncEnumerable<Song> Handle(Sing request, [Enumerator...
class SingSongPipelineBehavior (line 35) | public class SingSongPipelineBehavior : IStreamPipelineBehavior<Sing, ...
method Handle (line 37) | public async IAsyncEnumerable<Song> Handle(Sing request, StreamHandl...
method Should_run_pipeline_behavior (line 50) | [Fact]
FILE: test/MediatR.Tests/PipelineTests.cs
class PipelineTests (line 10) | public class PipelineTests
class Ping (line 12) | public class Ping : IRequest<Pong>
class Pong (line 17) | public class Pong
class VoidPing (line 22) | public class VoidPing : IRequest
class Zing (line 27) | public class Zing : IRequest<Zong>
class Zong (line 32) | public class Zong
class PingHandler (line 37) | public class PingHandler : IRequestHandler<Ping, Pong>
method PingHandler (line 41) | public PingHandler(Logger output)
method Handle (line 45) | public Task<Pong> Handle(Ping request, CancellationToken cancellatio...
class VoidPingHandler (line 52) | public class VoidPingHandler : IRequestHandler<VoidPing>
method VoidPingHandler (line 56) | public VoidPingHandler(Logger output)
method Handle (line 60) | public Task Handle(VoidPing request, CancellationToken cancellationT...
class ZingHandler (line 67) | public class ZingHandler : IRequestHandler<Zing, Zong>
method ZingHandler (line 71) | public ZingHandler(Logger output)
method Handle (line 75) | public Task<Zong> Handle(Zing request, CancellationToken cancellatio...
class OuterBehavior (line 82) | public class OuterBehavior : IPipelineBehavior<Ping, Pong>
method OuterBehavior (line 86) | public OuterBehavior(Logger output)
method Handle (line 91) | public async Task<Pong> Handle(Ping request, RequestHandlerDelegate<...
method OuterBehavior (line 182) | public OuterBehavior(Logger output)
method Handle (line 187) | public async Task<TResponse> Handle(TRequest request, RequestHandler...
class OuterVoidBehavior (line 101) | public class OuterVoidBehavior : IPipelineBehavior<VoidPing, Unit>
method OuterVoidBehavior (line 105) | public OuterVoidBehavior(Logger output)
method Handle (line 110) | public async Task<Unit> Handle(VoidPing request, RequestHandlerDeleg...
class InnerBehavior (line 120) | public class InnerBehavior : IPipelineBehavior<Ping, Pong>
method InnerBehavior (line 124) | public InnerBehavior(Logger output)
method Handle (line 129) | public async Task<Pong> Handle(Ping request, RequestHandlerDelegate<...
method InnerBehavior (line 163) | public InnerBehavior(Logger output)
method Handle (line 168) | public async Task<TResponse> Handle(TRequest request, RequestHandler...
class InnerVoidBehavior (line 139) | public class InnerVoidBehavior : IPipelineBehavior<VoidPing, Unit>
method InnerVoidBehavior (line 143) | public InnerVoidBehavior(Logger output)
method Handle (line 148) | public async Task<Unit> Handle(VoidPing request, RequestHandlerDeleg...
class InnerBehavior (line 158) | public class InnerBehavior<TRequest, TResponse> : IPipelineBehavior<TR...
method InnerBehavior (line 124) | public InnerBehavior(Logger output)
method Handle (line 129) | public async Task<Pong> Handle(Ping request, RequestHandlerDelegate<...
method InnerBehavior (line 163) | public InnerBehavior(Logger output)
method Handle (line 168) | public async Task<TResponse> Handle(TRequest request, RequestHandler...
class OuterBehavior (line 178) | public class OuterBehavior<TRequest, TResponse> : IPipelineBehavior<TR...
method OuterBehavior (line 86) | public OuterBehavior(Logger output)
method Handle (line 91) | public async Task<Pong> Handle(Ping request, RequestHandlerDelegate<...
method OuterBehavior (line 182) | public OuterBehavior(Logger output)
method Handle (line 187) | public async Task<TResponse> Handle(TRequest request, RequestHandler...
class ConstrainedBehavior (line 197) | public class ConstrainedBehavior<TRequest, TResponse> : IPipelineBehav...
method ConstrainedBehavior (line 203) | public ConstrainedBehavior(Logger output)
method Handle (line 208) | public async Task<TResponse> Handle(TRequest request, RequestHandler...
class ConcreteBehavior (line 218) | public class ConcreteBehavior : IPipelineBehavior<Ping, Pong>
method ConcreteBehavior (line 222) | public ConcreteBehavior(Logger output)
method Handle (line 227) | public async Task<Pong> Handle(Ping request, RequestHandlerDelegate<...
class Logger (line 237) | public class Logger
method Should_wrap_with_behavior (line 242) | [Fact]
method Should_wrap_void_with_behavior (line 275) | [Fact]
method Should_wrap_generics_with_behavior (line 306) | [Fact]
method Should_wrap_void_generics_with_behavior (line 341) | [Fact]
method Should_handle_constrained_generics (line 375) | [Fact]
method Should_handle_concrete_and_open_generics (line 430) | [Fact(Skip = "Lamar does not mix concrete and open generics. Use const...
FILE: test/MediatR.Tests/PublishTests.cs
class PublishTests (line 13) | public class PublishTests
class Ping (line 15) | public class Ping : INotification
class PongHandler (line 20) | public class PongHandler : INotificationHandler<Ping>
method PongHandler (line 24) | public PongHandler(TextWriter writer)
method Handle (line 29) | public Task Handle(Ping notification, CancellationToken cancellation...
class PungHandler (line 35) | public class PungHandler : INotificationHandler<Ping>
method PungHandler (line 39) | public PungHandler(TextWriter writer)
method Handle (line 44) | public Task Handle(Ping notification, CancellationToken cancellation...
method Should_resolve_main_handler (line 50) | [Fact]
method Should_resolve_main_handler_when_object_is_passed (line 76) | [Fact]
class SequentialMediator (line 103) | public class SequentialMediator : Mediator
method SequentialMediator (line 105) | public SequentialMediator(IServiceProvider serviceProvider)
method PublishCore (line 110) | protected override async Task PublishCore(IEnumerable<NotificationHa...
class SequentialPublisher (line 119) | public class SequentialPublisher : INotificationPublisher
method Publish (line 123) | public async Task Publish(IEnumerable<NotificationHandlerExecutor> h...
method Should_override_with_sequential_firing (line 133) | [Fact]
method Should_override_with_sequential_firing_through_injection (line 159) | [Fact]
method Should_resolve_handlers_given_interface (line 188) | [Fact]
method Should_resolve_main_handler_by_specific_interface (line 216) | [Fact]
FILE: test/MediatR.Tests/SendTests.cs
class SendTests (line 12) | public class SendTests
method SendTests (line 18) | public SendTests()
class Ping (line 34) | public class Ping : IRequest<Pong>
class VoidPing (line 39) | public class VoidPing : IRequest
class Pong (line 43) | public class Pong
class PingHandler (line 48) | public class PingHandler : IRequestHandler<Ping, Pong>
method Handle (line 50) | public Task<Pong> Handle(Ping request, CancellationToken cancellatio...
class Dependency (line 56) | public class Dependency
class VoidPingHandler (line 62) | public class VoidPingHandler : IRequestHandler<VoidPing>
method VoidPingHandler (line 66) | public VoidPingHandler(Dependency dependency) => _dependency = depen...
method Handle (line 68) | public Task Handle(VoidPing request, CancellationToken cancellationT...
class GenericPing (line 76) | public class GenericPing<T> : IRequest<T>
class GenericPingHandler (line 82) | public class GenericPingHandler<T> : IRequestHandler<GenericPing<T>, T>
method GenericPingHandler (line 87) | public GenericPingHandler(Dependency dependency) => _dependency = de...
method Handle (line 89) | public Task<T> Handle(GenericPing<T> request, CancellationToken canc...
class VoidGenericPing (line 97) | public class VoidGenericPing<T> : IRequest
class VoidGenericPingHandler (line 101) | public class VoidGenericPingHandler<T> : IRequestHandler<VoidGenericPi...
method VoidGenericPingHandler (line 105) | public VoidGenericPingHandler(Dependency dependency) => _dependency ...
method Handle (line 107) | public Task Handle(VoidGenericPing<T> request, CancellationToken can...
class PongExtension (line 115) | public class PongExtension : Pong
class TestClass1PingRequestHandler (line 120) | public class TestClass1PingRequestHandler : IRequestHandler<VoidGeneri...
method TestClass1PingRequestHandler (line 124) | public TestClass1PingRequestHandler(Dependency dependency) => _depen...
method Handle (line 126) | public Task Handle(VoidGenericPing<PongExtension> request, Cancellat...
type ITestInterface1 (line 133) | public interface ITestInterface1 { }
type ITestInterface2 (line 134) | public interface ITestInterface2 { }
type ITestInterface3 (line 135) | public interface ITestInterface3 { }
class TestClass1 (line 137) | public class TestClass1 : ITestInterface1 { }
class TestClass2 (line 138) | public class TestClass2 : ITestInterface2 { }
class TestClass3 (line 139) | public class TestClass3 : ITestInterface3 { }
class MultipleGenericTypeParameterRequest (line 141) | public class MultipleGenericTypeParameterRequest<T1, T2, T3> : IReques...
class MultipleGenericTypeParameterRequestHandler (line 149) | public class MultipleGenericTypeParameterRequestHandler<T1, T2, T3> : ...
method MultipleGenericTypeParameterRequestHandler (line 156) | public MultipleGenericTypeParameterRequestHandler(Dependency depende...
method Handle (line 158) | public Task<int> Handle(MultipleGenericTypeParameterRequest<T1, T2, ...
class TimeoutBehavior (line 165) | public class TimeoutBehavior<TRequest, TResponse> : IPipelineBehavior<...
method Handle (line 168) | public async Task<TResponse> Handle(TRequest request, RequestHandler...
class TimeoutRequest (line 177) | public class TimeoutRequest : IRequest
class TimeoutRequest2 (line 181) | public class TimeoutRequest2 : IRequest<int>
class TimeoutRequestHandler (line 185) | public class TimeoutRequestHandler : IRequestHandler<TimeoutRequest>
method TimeoutRequestHandler (line 189) | public TimeoutRequestHandler(Dependency dependency) => _dependency =...
method Handle (line 191) | public async Task Handle(TimeoutRequest request, CancellationToken c...
class TimeoutRequest2Handler (line 199) | public class TimeoutRequest2Handler : IRequestHandler<TimeoutRequest2,...
method TimeoutRequest2Handler (line 203) | public TimeoutRequest2Handler(Dependency dependency) => _dependency ...
method Handle (line 205) | public async Task<int> Handle(TimeoutRequest2 request, CancellationT...
method Should_resolve_main_handler (line 214) | [Fact]
method Should_resolve_main_void_handler (line 222) | [Fact]
method Should_resolve_main_handler_via_dynamic_dispatch (line 230) | [Fact]
method Should_resolve_main_void_handler_via_dynamic_dispatch (line 240) | [Fact]
method Should_resolve_main_handler_by_specific_interface (line 251) | [Fact]
method Should_resolve_main_handler_by_given_interface (line 259) | [Fact]
method Should_raise_execption_on_null_request (line 269) | [Fact]
method Should_resolve_generic_handler (line 272) | [Fact]
method Should_resolve_generic_void_handler (line 284) | [Fact]
method Should_resolve_multiple_type_parameter_generic_handler (line 293) | [Fact]
method Should_resolve_closed_handler_if_defined (line 302) | [Fact]
method Should_resolve_open_handler_if_not_defined (line 326) | [Fact]
method TimeoutBehavior_Void_Should_Cancel_Long_Running_Task_And_Throw_Exception (line 349) | [Fact]
method TimeoutBehavior_NonVoid_Should_Cancel_Long_Running_Task_And_Throw_Exception (line 361) | [Fact]
FILE: test/MediatR.Tests/SendVoidInterfaceTests.cs
class SendVoidInterfaceTests (line 11) | public class SendVoidInterfaceTests
class Ping (line 13) | public class Ping : IRequest
class PingHandler (line 18) | public class PingHandler : IRequestHandler<Ping>
method PingHandler (line 22) | public PingHandler(TextWriter writer) => _writer = writer;
method Handle (line 24) | public Task Handle(Ping request, CancellationToken cancellationToken)
method Should_resolve_main_void_handler (line 28) | [Fact]
FILE: test/MediatR.Tests/ServiceFactoryTests.cs
class ServiceFactoryCollectionBehavior (line 12) | [CollectionDefinition(nameof(ServiceFactoryCollectionBehavior), DisableP...
class ServiceFactoryTests (line 15) | [Collection(nameof(ServiceFactoryCollectionBehavior))]
class Ping (line 18) | public class Ping : IRequest<Pong>
class Pong (line 23) | public class Pong
method Should_throw_given_no_handler (line 28) | [Fact]
method Should_not_throw_with_manual_registration (line 46) | [Fact]
method Should_throw_when_missing_required_configuration (line 64) | [Fact]
FILE: test/MediatR.Tests/StreamPipelineTests.cs
class StreamPipelineTests (line 11) | public class StreamPipelineTests
class Ping (line 13) | public class Ping : IStreamRequest<Pong>
class Pong (line 18) | public class Pong
class Zing (line 23) | public class Zing : IStreamRequest<Zong>
class Zong (line 28) | public class Zong
class PingHandler (line 33) | public class PingHandler : IStreamRequestHandler<Ping, Pong>
method PingHandler (line 37) | public PingHandler(Logger output)
method Handle (line 42) | public async IAsyncEnumerable<Pong> Handle(Ping request, [Enumerator...
class ZingHandler (line 49) | public class ZingHandler : IStreamRequestHandler<Zing, Zong>
method ZingHandler (line 53) | public ZingHandler(Logger output)
method Handle (line 58) | public async IAsyncEnumerable<Zong> Handle(Zing request, [Enumerator...
class OuterBehavior (line 65) | public class OuterBehavior : IStreamPipelineBehavior<Ping, Pong>
method OuterBehavior (line 69) | public OuterBehavior(Logger output)
method Handle (line 74) | public async IAsyncEnumerable<Pong> Handle(Ping request, StreamHandl...
method OuterBehavior (line 131) | public OuterBehavior(Logger output)
method Handle (line 136) | public async IAsyncEnumerable<TResponse> Handle(TRequest request, St...
class InnerBehavior (line 85) | public class InnerBehavior : IStreamPipelineBehavior<Ping, Pong>
method InnerBehavior (line 89) | public InnerBehavior(Logger output)
method Handle (line 94) | public async IAsyncEnumerable<Pong> Handle(Ping request, StreamHandl...
method InnerBehavior (line 110) | public InnerBehavior(Logger output)
method Handle (line 115) | public async IAsyncEnumerable<TResponse> Handle(TRequest request, St...
class InnerBehavior (line 105) | public class InnerBehavior<TRequest, TResponse> : IStreamPipelineBehav...
method InnerBehavior (line 89) | public InnerBehavior(Logger output)
method Handle (line 94) | public async IAsyncEnumerable<Pong> Handle(Ping request, StreamHandl...
method InnerBehavior (line 110) | public InnerBehavior(Logger output)
method Handle (line 115) | public async IAsyncEnumerable<TResponse> Handle(TRequest request, St...
class OuterBehavior (line 126) | public class OuterBehavior<TRequest, TResponse> : IStreamPipelineBehav...
method OuterBehavior (line 69) | public OuterBehavior(Logger output)
method Handle (line 74) | public async IAsyncEnumerable<Pong> Handle(Ping request, StreamHandl...
method OuterBehavior (line 131) | public OuterBehavior(Logger output)
method Handle (line 136) | public async IAsyncEnumerable<TResponse> Handle(TRequest request, St...
class ConstrainedBehavior (line 147) | public class ConstrainedBehavior<TRequest, TResponse> : IStreamPipelin...
method ConstrainedBehavior (line 153) | public ConstrainedBehavior(Logger output)
method Handle (line 157) | public async IAsyncEnumerable<TResponse> Handle(TRequest request, St...
class ConcreteBehavior (line 168) | public class ConcreteBehavior : IStreamPipelineBehavior<Ping, Pong>
method ConcreteBehavior (line 172) | public ConcreteBehavior(Logger output)
method Handle (line 177) | public async IAsyncEnumerable<Pong> Handle(Ping request, StreamHandl...
class Logger (line 188) | public class Logger
method Should_wrap_with_behavior (line 193) | [Fact]
method Should_wrap_generics_with_behavior (line 227) | [Fact]
method Should_handle_constrained_generics (line 263) | [Fact]
method Should_handle_concrete_and_open_generics (line 318) | [Fact(Skip = "Lamar does not mix concrete and open generics. Use const...
FILE: test/MediatR.Tests/TestContainer.cs
class TestContainer (line 8) | public static class TestContainer
method Create (line 10) | public static IServiceProvider Create(Action<ServiceCollection> config)
FILE: test/MediatR.Tests/UnitTests.cs
class UnitTests (line 9) | public class UnitTests
method Should_be_equal_to_each_other (line 11) | [Fact]
method Should_be_equitable (line 22) | [Fact]
method Should_tostring (line 33) | [Fact]
method Should_compareto_as_zero (line 40) | [Fact]
method ValueData (line 49) | public static object[][] ValueData()
method CompareToValueData (line 65) | public static object[][] CompareToValueData()
method Should_be_equal (line 68) | [Theory]
method Should_compareto_value_as_zero (line 80) | [Theory]
Condensed preview — 182 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (480K chars).
[
{
"path": ".editorconfig",
"chars": 3151,
"preview": "root=true\n; EditorConfig helps developers define and maintain consistent\n; coding styles between different editors and I"
},
{
"path": ".gitattributes",
"chars": 437,
"preview": "*.doc diff=astextplain\n*.DOC\tdiff=astextplain\n*.docx\tdiff=astextplain\n*.DOCX\tdiff=astextplain\n*.dot\tdiff=astextplain\n*."
},
{
"path": ".github/workflows/ci.yml",
"chars": 2059,
"preview": "name: CI\n\non:\n workflow_dispatch: \n push:\n branches:\n - main\n pull_request:\nenv:\n DOTNET_NOLOGO: true\n DOTNET"
},
{
"path": ".github/workflows/release.yml",
"chars": 2865,
"preview": "name: Release\n\non:\n push:\n tags:\n - '*.*.*'\nenv:\n DOTNET_NOLOGO: true\n DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true\n"
},
{
"path": ".github/workflows/triage-issues.yml",
"chars": 1700,
"preview": "# https://github.com/actions/stale\n\nname: \"Stale issue & PR handler\"\n\non:\n workflow_dispatch:\n schedule:\n - cron: \""
},
{
"path": ".gitignore",
"chars": 3482,
"preview": "## Ignore Visual Studio temporary files, build results, and\n## files generated by popular Visual Studio add-ons.\n\n# User"
},
{
"path": "Build.ps1",
"chars": 1126,
"preview": "# Taken from psake https://github.com/psake/psake\n\n<#\n.SYNOPSIS\n This is a helper function that runs a scriptblock and "
},
{
"path": "BuildContracts.ps1",
"chars": 1156,
"preview": "# Taken from psake https://github.com/psake/psake\n\n<#\n.SYNOPSIS\n This is a helper function that runs a scriptblock and "
},
{
"path": "Directory.Build.props",
"chars": 516,
"preview": "<Project>\n <PropertyGroup>\n <IsMac>$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Run"
},
{
"path": "LICENSE.md",
"chars": 746,
"preview": "By accessing code under the [Lucky Penny Software GitHub Organization](https://github.com/LuckyPennySoftware) (Lucky Pen"
},
{
"path": "MediatR.slnx",
"chars": 1691,
"preview": "<Solution>\n <Folder Name=\"/samples/\">\n <Project Path=\"samples/MediatR.Examples.AspNetCore/MediatR.Examples.AspNetCor"
},
{
"path": "NuGet.Config",
"chars": 203,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<configuration>\n <packageSources>\n <add key=\"nuget.org\" value=\"https://api.n"
},
{
"path": "Push.ps1",
"chars": 545,
"preview": "$scriptName = $MyInvocation.MyCommand.Name\n$artifacts = \"./artifacts\"\n\nif ([string]::IsNullOrEmpty($Env:NUGET_API_KEY)) "
},
{
"path": "README.md",
"chars": 3703,
"preview": "MediatR\n=======\n\n\n[)]\n[assembly: Typ"
},
{
"path": "src/MediatR/Wrappers/NotificationHandlerWrapper.cs",
"chars": 1292,
"preview": "namespace MediatR.Wrappers;\n\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Threading;\n"
},
{
"path": "src/MediatR/Wrappers/RequestHandlerWrapper.cs",
"chars": 2972,
"preview": "using System;\nusing System.Linq;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing Microsoft.Extensions.Depend"
},
{
"path": "src/MediatR/Wrappers/StreamRequestHandlerWrapper.cs",
"chars": 2643,
"preview": "using System;\nusing Microsoft.Extensions.DependencyInjection;\n\nnamespace MediatR.Wrappers;\n\nusing System.Collections.Gen"
},
{
"path": "src/MediatR/license.txt",
"chars": 746,
"preview": "By accessing code under the [Lucky Penny Software GitHub Organization](https://github.com/LuckyPennySoftware) (Lucky Pen"
},
{
"path": "src/MediatR.Contracts/INotification.cs",
"chars": 132,
"preview": "namespace MediatR;\n\n/// <summary>\n/// Marker interface to represent a notification\n/// </summary>\npublic interface INoti"
},
{
"path": "src/MediatR.Contracts/IRequest.cs",
"chars": 526,
"preview": "namespace MediatR;\n\n/// <summary>\n/// Marker interface to represent a request with a void response\n/// </summary>\npublic"
},
{
"path": "src/MediatR.Contracts/IStreamRequest.cs",
"chars": 228,
"preview": "namespace MediatR;\n\n/// <summary>\n/// Marker interface to represent a request with a streaming response\n/// </summary>\n/"
},
{
"path": "src/MediatR.Contracts/MediatR.Contracts.csproj",
"chars": 1335,
"preview": "<Project Sdk=\"Microsoft.NET.Sdk\">\n\n <PropertyGroup>\n <Nullable>enable</Nullable>\n <Authors>Jimmy Bogard</Authors"
},
{
"path": "src/MediatR.Contracts/Unit.cs",
"chars": 4463,
"preview": "namespace MediatR;\n\nusing System;\nusing System.Threading.Tasks;\n\n/// <summary>\n/// Represents a void type, since <see c"
},
{
"path": "test/MediatR.Benchmarks/Benchmarks.cs",
"chars": 1194,
"preview": "using System.IO;\nusing System.Threading.Tasks;\nusing BenchmarkDotNet.Attributes;\nusing Microsoft.Extensions.DependencyIn"
},
{
"path": "test/MediatR.Benchmarks/DotTraceDiagnoser.cs",
"chars": 4676,
"preview": "using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.IO;\nusing System.Linq;\nusing Benc"
},
{
"path": "test/MediatR.Benchmarks/GenericPipelineBehavior.cs",
"chars": 766,
"preview": "using System.IO;\nusing System.Threading;\nusing System.Threading.Tasks;\n\nnamespace MediatR.Benchmarks\n{\n public class "
},
{
"path": "test/MediatR.Benchmarks/GenericRequestPostProcessor.cs",
"chars": 623,
"preview": "using System.IO;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing MediatR.Pipeline;\n\nnamespace MediatR.Benchm"
},
{
"path": "test/MediatR.Benchmarks/GenericRequestPreProcessor.cs",
"chars": 581,
"preview": "using System.IO;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing MediatR.Pipeline;\n\nnamespace MediatR.Benchm"
},
{
"path": "test/MediatR.Benchmarks/MediatR.Benchmarks.csproj",
"chars": 814,
"preview": "<Project Sdk=\"Microsoft.NET.Sdk\">\n <PropertyGroup>\n <TargetFramework>net10.0</TargetFramework>\n <OutputType>Exe</"
},
{
"path": "test/MediatR.Benchmarks/Ping.cs",
"chars": 343,
"preview": "using System.Threading;\nusing System.Threading.Tasks;\n\nnamespace MediatR.Benchmarks\n{\n public class Ping : IRequest\n "
},
{
"path": "test/MediatR.Benchmarks/Pinged.cs",
"chars": 358,
"preview": "using System.Threading;\nusing System.Threading.Tasks;\n\nnamespace MediatR.Benchmarks\n{\n public class Pinged : INotific"
},
{
"path": "test/MediatR.Benchmarks/Program.cs",
"chars": 219,
"preview": "using BenchmarkDotNet.Running;\n\nnamespace MediatR.Benchmarks\n{\n public class Program\n {\n public static void"
},
{
"path": "test/MediatR.DependencyInjectionTests/Abstractions/BaseAssemblyResolutionTests.cs",
"chars": 2354,
"preview": "using MediatR.DependencyInjectionTests.Contracts.Notifications;\nusing MediatR.DependencyInjectionTests.Contracts.Stream"
},
{
"path": "test/MediatR.DependencyInjectionTests/Abstractions/BaseServiceProviderFixture.cs",
"chars": 187,
"preview": "namespace MediatR.DependencyInjectionTests.Abstractions;\n\npublic class BaseServiceProviderFixture\n{\n public virtual "
},
{
"path": "test/MediatR.DependencyInjectionTests/AutoFacDependencyInjectionTests.cs",
"chars": 321,
"preview": "using MediatR.DependencyInjectionTests.Abstractions;\nusing MediatR.DependencyInjectionTests.Providers;\n\nnamespace Media"
},
{
"path": "test/MediatR.DependencyInjectionTests/Contracts/Notifications/Ding.cs",
"chars": 659,
"preview": "namespace MediatR.DependencyInjectionTests.Contracts.Notifications;\n\npublic record Ding : INotification\n{\n public cl"
},
{
"path": "test/MediatR.DependencyInjectionTests/Contracts/Requests/InternalPing.cs",
"chars": 327,
"preview": "namespace MediatR.DependencyInjectionTests.Contracts.Requests;\n\ninternal record InternalPing : IRequest<Pong>\n{\n int"
},
{
"path": "test/MediatR.DependencyInjectionTests/Contracts/Requests/InternalVoidPing.cs",
"chars": 312,
"preview": "namespace MediatR.DependencyInjectionTests.Contracts.Requests;\n\ninternal record InternalVoidPing : IRequest\n{\n inter"
},
{
"path": "test/MediatR.DependencyInjectionTests/Contracts/Requests/PrivatePing.cs",
"chars": 321,
"preview": "namespace MediatR.DependencyInjectionTests.Contracts.Requests;\n\npublic record PrivatePing : IRequest<Pong>\n{\n privat"
},
{
"path": "test/MediatR.DependencyInjectionTests/Contracts/Requests/PrivateVoidPing.cs",
"chars": 306,
"preview": "namespace MediatR.DependencyInjectionTests.Contracts.Requests;\n\npublic record PrivateVoidPing : IRequest\n{\n private "
},
{
"path": "test/MediatR.DependencyInjectionTests/Contracts/Requests/PublicPing.cs",
"chars": 317,
"preview": "namespace MediatR.DependencyInjectionTests.Contracts.Requests;\n\npublic record PublicPing : IRequest<Pong>\n{\n public "
},
{
"path": "test/MediatR.DependencyInjectionTests/Contracts/Requests/PublicVoidPing.cs",
"chars": 302,
"preview": "namespace MediatR.DependencyInjectionTests.Contracts.Requests;\n\npublic record PublicVoidPing : IRequest\n{\n public cl"
},
{
"path": "test/MediatR.DependencyInjectionTests/Contracts/Responses/Pong.cs",
"chars": 106,
"preview": "namespace MediatR.DependencyInjectionTests.Contracts.Responses;\n\npublic record Pong;\npublic record Zong;\n"
},
{
"path": "test/MediatR.DependencyInjectionTests/Contracts/StreamRequests/InternalZing.cs",
"chars": 353,
"preview": "namespace MediatR.DependencyInjectionTests.Contracts.StreamRequests;\n\ninternal record InternalZing : IStreamRequest<Zon"
},
{
"path": "test/MediatR.DependencyInjectionTests/Contracts/StreamRequests/PrivateZing.cs",
"chars": 349,
"preview": "namespace MediatR.DependencyInjectionTests.Contracts.StreamRequests;\n\ninternal record PrivateZing : IStreamRequest<Zong"
},
{
"path": "test/MediatR.DependencyInjectionTests/Contracts/StreamRequests/PublicZing.cs",
"chars": 343,
"preview": "namespace MediatR.DependencyInjectionTests.Contracts.StreamRequests;\n\npublic record PublicZing : IStreamRequest<Zong>\n{"
},
{
"path": "test/MediatR.DependencyInjectionTests/DryIocDependencyInjectionTests.cs",
"chars": 267,
"preview": "using MediatR.DependencyInjectionTests.Abstractions;\nusing MediatR.DependencyInjectionTests.Providers;\n\nnamespace Media"
},
{
"path": "test/MediatR.DependencyInjectionTests/LamarDependencyInjectionTests.cs",
"chars": 264,
"preview": "using MediatR.DependencyInjectionTests.Abstractions;\nusing MediatR.DependencyInjectionTests.Providers;\n\nnamespace Mediat"
},
{
"path": "test/MediatR.DependencyInjectionTests/LightInjectDependencyInjectionTests.cs",
"chars": 276,
"preview": "using MediatR.DependencyInjectionTests.Abstractions;\nusing MediatR.DependencyInjectionTests.Providers;\n\nnamespace Mediat"
},
{
"path": "test/MediatR.DependencyInjectionTests/MediatR.DependencyInjectionTests.csproj",
"chars": 1566,
"preview": "<Project Sdk=\"Microsoft.NET.Sdk\">\n\n <PropertyGroup>\n <TargetFramework>net10.0</TargetFramework>\n <Impl"
},
{
"path": "test/MediatR.DependencyInjectionTests/MicrosoftDependencyInjectionTests.cs",
"chars": 327,
"preview": "using MediatR.DependencyInjectionTests.Abstractions;\nusing MediatR.DependencyInjectionTests.Providers;\n\nnamespace Media"
},
{
"path": "test/MediatR.DependencyInjectionTests/Providers/AutoFacServiceProviderFixture.cs",
"chars": 764,
"preview": "using Autofac;\nusing Autofac.Extensions.DependencyInjection;\nusing MediatR.DependencyInjectionTests.Abstractions;\nusing"
},
{
"path": "test/MediatR.DependencyInjectionTests/Providers/DryIocServiceProviderFixture.cs",
"chars": 767,
"preview": "using DryIoc;\nusing DryIoc.Microsoft.DependencyInjection;\nusing MediatR.DependencyInjectionTests.Abstractions;\nusing Mi"
},
{
"path": "test/MediatR.DependencyInjectionTests/Providers/LamarServiceProviderFixture.cs",
"chars": 601,
"preview": "using Lamar;\nusing MediatR.DependencyInjectionTests.Abstractions;\nusing Microsoft.Extensions.DependencyInjection;\n\nnames"
},
{
"path": "test/MediatR.DependencyInjectionTests/Providers/LightInjectServiceProviderFixture.cs",
"chars": 796,
"preview": "using LightInject;\nusing LightInject.Microsoft.DependencyInjection;\nusing MediatR.DependencyInjectionTests.Abstractions;"
},
{
"path": "test/MediatR.DependencyInjectionTests/Providers/MicrosoftServiceProviderFixture.cs",
"chars": 457,
"preview": "using MediatR.DependencyInjectionTests.Abstractions;\nusing Microsoft.Extensions.DependencyInjection;\n\nnamespace MediatR"
},
{
"path": "test/MediatR.DependencyInjectionTests/Providers/StashBoxServiceProviderFixture.cs",
"chars": 710,
"preview": "using MediatR.DependencyInjectionTests.Abstractions;\nusing Microsoft.Extensions.DependencyInjection;\nusing Stashbox;\n\nna"
},
{
"path": "test/MediatR.DependencyInjectionTests/StashBoxDependencyInjectionTests.cs",
"chars": 323,
"preview": "using MediatR.DependencyInjectionTests.Abstractions;\nusing MediatR.DependencyInjectionTests.Providers;\n\nnamespace Mediat"
},
{
"path": "test/MediatR.DependencyInjectionTests/Usings.cs",
"chars": 156,
"preview": "global using MediatR.DependencyInjectionTests.Contracts.Requests;\nglobal using MediatR.DependencyInjectionTests.Contrac"
},
{
"path": "test/MediatR.Tests/CreateStreamTests.cs",
"chars": 4090,
"preview": "using System.Threading;\n\nnamespace MediatR.Tests;\n\nusing System;\nusing System.Collections.Generic;\nusing System.Runtime."
},
{
"path": "test/MediatR.Tests/ExceptionTests.cs",
"chars": 9061,
"preview": "using System.Threading;\n\nnamespace MediatR.Tests;\n\nusing System;\nusing System.Threading.Tasks;\nusing Shouldly;\nusing Xun"
},
{
"path": "test/MediatR.Tests/GenericRequestHandlerTests.cs",
"chars": 8207,
"preview": "using System.Linq;\r\nusing MediatR.Tests.MicrosoftExtensionsDI;\r\n\r\nnamespace MediatR.Tests\r\n{\r\n [Collection(nameof(Se"
},
{
"path": "test/MediatR.Tests/GenericTypeConstraintsTests.cs",
"chars": 4948,
"preview": "using System.Reflection;\nusing System.Threading;\n\nnamespace MediatR.Tests;\n\nusing System;\nusing System.Linq;\nusing Shoul"
},
{
"path": "test/MediatR.Tests/GlobalUsings.cs",
"chars": 187,
"preview": "global using Microsoft.Extensions.DependencyInjection;\nglobal using Shouldly;\nglobal using System;\nglobal using System.T"
},
{
"path": "test/MediatR.Tests/Licensing/LicenseValidatorTests.cs",
"chars": 11147,
"preview": "using System;\nusing System.Security.Claims;\nusing MediatR.Licensing;\nusing Microsoft.Extensions.Logging;\nusing Microsoft"
},
{
"path": "test/MediatR.Tests/MediatR.Tests.csproj",
"chars": 1735,
"preview": "<Project Sdk=\"Microsoft.NET.Sdk\">\n\n <PropertyGroup>\n <TargetFrameworks>net10.0</TargetFrameworks>\n <Nullable>ena"
},
{
"path": "test/MediatR.Tests/MicrosoftExtensionsDI/AssemblyResolutionTests.cs",
"chars": 3433,
"preview": "using Microsoft.Extensions.DependencyInjection;\n\nnamespace MediatR.Extensions.Microsoft.DependencyInjection.Tests;\n\nusi"
},
{
"path": "test/MediatR.Tests/MicrosoftExtensionsDI/BaseGenericRequestHandlerTests.cs",
"chars": 10000,
"preview": "using System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Reflection.Emit;\r\nusing System.Refle"
},
{
"path": "test/MediatR.Tests/MicrosoftExtensionsDI/CustomMediatorTests.cs",
"chars": 2059,
"preview": "using Microsoft.Extensions.DependencyInjection;\n\nnamespace MediatR.Extensions.Microsoft.DependencyInjection.Tests;\n\nusi"
},
{
"path": "test/MediatR.Tests/MicrosoftExtensionsDI/DerivingRequestsTests.cs",
"chars": 1117,
"preview": "using System;\nusing System.Threading.Tasks;\nusing Microsoft.Extensions.DependencyInjection;\nusing Shouldly;\nusing Xunit"
},
{
"path": "test/MediatR.Tests/MicrosoftExtensionsDI/DuplicateAssemblyResolutionTests.cs",
"chars": 773,
"preview": "using Microsoft.Extensions.DependencyInjection;\n\nnamespace MediatR.Extensions.Microsoft.DependencyInjection.Tests;\n\nusi"
},
{
"path": "test/MediatR.Tests/MicrosoftExtensionsDI/Handlers.cs",
"chars": 8754,
"preview": "using System;\nusing System.Runtime.CompilerServices;\n\nnamespace MediatR.Extensions.Microsoft.DependencyInjection.Tests\n"
},
{
"path": "test/MediatR.Tests/MicrosoftExtensionsDI/Issue1118Tests.cs",
"chars": 3778,
"preview": "using System.Collections.Generic;\nusing System.Linq;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing Microso"
},
{
"path": "test/MediatR.Tests/MicrosoftExtensionsDI/NotificationPublisherTests.cs",
"chars": 3794,
"preview": "using Microsoft.Extensions.DependencyInjection;\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusin"
},
{
"path": "test/MediatR.Tests/MicrosoftExtensionsDI/PipeLineMultiCallToConstructorTest.cs",
"chars": 3405,
"preview": "using System.Threading;\nusing Microsoft.Extensions.DependencyInjection;\n\nnamespace MediatR.Extensions.Microsoft.Depende"
},
{
"path": "test/MediatR.Tests/MicrosoftExtensionsDI/PipelineTests.cs",
"chars": 42374,
"preview": "using System.Runtime.CompilerServices;\n\nnamespace MediatR.Extensions.Microsoft.DependencyInjection.Tests;\n\nusing System"
},
{
"path": "test/MediatR.Tests/MicrosoftExtensionsDI/StreamPipelineTests.cs",
"chars": 3849,
"preview": "using System.Runtime.CompilerServices;\nusing Microsoft.Extensions.DependencyInjection;\n\nnamespace MediatR.Extensions.Mi"
},
{
"path": "test/MediatR.Tests/MicrosoftExtensionsDI/TypeEvaluatorTests.cs",
"chars": 1818,
"preview": "using System.Linq;\nusing Microsoft.Extensions.DependencyInjection;\n\nnamespace MediatR.Extensions.Microsoft.DependencyIn"
},
{
"path": "test/MediatR.Tests/MicrosoftExtensionsDI/TypeResolutionTests.cs",
"chars": 2723,
"preview": "using System.Collections.Generic;\nusing Microsoft.Extensions.DependencyInjection;\n\nnamespace MediatR.Extensions.Microso"
},
{
"path": "test/MediatR.Tests/NotificationHandlerTests.cs",
"chars": 1064,
"preview": "using System.IO;\nusing System.Text;\nusing System.Threading.Tasks;\nusing Shouldly;\nusing Xunit;\n\nnamespace MediatR.Tests;"
},
{
"path": "test/MediatR.Tests/NotificationPublisherTests.cs",
"chars": 2238,
"preview": "using System.Diagnostics;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing MediatR.NotificationPublishers;\nu"
},
{
"path": "test/MediatR.Tests/Pipeline/RequestExceptionActionTests.cs",
"chars": 4579,
"preview": "using MediatR.Pipeline;\n\nnamespace MediatR.Tests.Pipeline;\n\npublic class RequestExceptionActionTests\n{\n public class "
},
{
"path": "test/MediatR.Tests/Pipeline/RequestExceptionHandlerTests.cs",
"chars": 6061,
"preview": "namespace MediatR.Tests.Pipeline;\n\nusing System;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing MediatR.Pip"
},
{
"path": "test/MediatR.Tests/Pipeline/RequestPostProcessorTests.cs",
"chars": 1645,
"preview": "using System.Threading;\n\nnamespace MediatR.Tests.Pipeline;\n\nusing System.Threading.Tasks;\nusing MediatR.Pipeline;\nusing "
},
{
"path": "test/MediatR.Tests/Pipeline/RequestPreProcessorTests.cs",
"chars": 1599,
"preview": "using System.Threading;\n\nnamespace MediatR.Tests.Pipeline;\n\nusing System.Threading.Tasks;\nusing MediatR.Pipeline;\nusing "
},
{
"path": "test/MediatR.Tests/Pipeline/Streams/StreamPipelineBehaviorTests.cs",
"chars": 2892,
"preview": "using System.Threading;\nusing MediatR.Registration;\nusing Microsoft.Extensions.DependencyInjection;\n\nnamespace MediatR.T"
},
{
"path": "test/MediatR.Tests/PipelineTests.cs",
"chars": 14685,
"preview": "using System.Threading;\n\nnamespace MediatR.Tests;\n\nusing System.Collections.Generic;\nusing System.Threading.Tasks;\nusing"
},
{
"path": "test/MediatR.Tests/PublishTests.cs",
"chars": 8148,
"preview": "using System.Threading;\n\nnamespace MediatR.Tests;\n\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusin"
},
{
"path": "test/MediatR.Tests/SendTests.cs",
"chars": 11831,
"preview": "using System.Threading;\r\n\r\nusing System;\r\nusing System.Threading.Tasks;\r\nusing Shouldly;\r\nusing Xunit;\r\nusing Microsoft."
},
{
"path": "test/MediatR.Tests/SendVoidInterfaceTests.cs",
"chars": 1501,
"preview": "using System.Threading;\n\nnamespace MediatR.Tests;\n\nusing System.IO;\nusing System.Text;\nusing System.Threading.Tasks;\nusi"
},
{
"path": "test/MediatR.Tests/ServiceFactoryTests.cs",
"chars": 2294,
"preview": "using System;\nusing System.Collections;\nusing System.Linq;\nusing System.Threading.Tasks;\nusing MediatR.Licensing;\nusing "
},
{
"path": "test/MediatR.Tests/StreamPipelineTests.cs",
"chars": 11798,
"preview": "using System.Threading;\n\nnamespace MediatR.Tests;\n\nusing System.Collections.Generic;\nusing System.Runtime.CompilerServic"
},
{
"path": "test/MediatR.Tests/TestContainer.cs",
"chars": 719,
"preview": "using MediatR.Licensing;\nusing MediatR.Registration;\nusing Microsoft.Extensions.Logging;\nusing Microsoft.Extensions.Logg"
},
{
"path": "test/MediatR.Tests/UnitTests.cs",
"chars": 2118,
"preview": "using System;\nusing System.Linq;\nusing System.Collections.Generic;\nusing System.Threading.Tasks;\nusing Xunit;\n\nnamespace"
}
]
// ... and 1 more files (download for full content)
About this extraction
This page contains the full source code of the LuckyPennySoftware/MediatR GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 182 files (438.7 KB), approximately 96.5k tokens, and a symbol index with 1064 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.