# luckypennysoftware/mediatr architecture

> Architecture diagram of the GitHub repository luckypennysoftware/mediatr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/luckypennysoftware/mediatr
- Repository: https://github.com/luckypennysoftware/mediatr

## Overview

MediatR is an in-process .NET messaging library: application code defines request, stream-request, and notification contracts, then sends or publishes through a mediator to handlers. Requests support behavior pipelines and stream dispatch; notifications fan out through a configurable publisher. Microsoft DI registration scans assemblies for handlers and behaviors. Licensing is a separate registration-time/mediator-construction concern. Dispatch internals are evidenced by the index and excerpts; unsampled subsystem links are omitted where call ownership is not shown.

Main entry points: [`src/MediatR/Mediator.cs`](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Mediator.cs) (Mediator), [`src/MediatR/MicrosoftExtensionsDI/MediatRServiceCollectionExtensions.cs`](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/MicrosoftExtensionsDI/MediatRServiceCollectionExtensions.cs) (DI extensions), [`src/MediatR/INotificationPublisher.cs`](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/INotificationPublisher.cs) (Notification publisher), [`src/MediatR/Wrappers/RequestHandlerWrapper.cs`](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Wrappers/RequestHandlerWrapper.cs) (Request dispatch)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_contracts["Contracts"]
  node_request_contracts["Request contracts<br/>[IRequest.cs]"]
  node_stream_contract["Stream contract<br/>[IStreamRequest.cs]"]
  node_notification_contract["Notification contract<br/>[INotification.cs]"]
end

subgraph group_dispatch["Dispatch"]
  node_mediator["Mediator<br/>[Mediator.cs]"]
  node_request_wrapper["Request dispatch"]
  node_request_handlers["Request handlers<br/>[IRequestHandler.cs]"]
  node_stream_wrapper["Stream dispatch"]
  node_stream_handlers["Stream handlers"]
  node_notification_wrapper["Notification dispatch"]
  node_notification_handlers["Notification handlers"]
  node_publisher["Notification publisher"]
  node_notification_executor["Handler executor"]
  node_foreach_publisher["Sequential publisher"]
  node_parallel_publisher["Parallel publisher"]
end

subgraph group_pipeline["Pipelines"]
  node_request_behavior["Request behaviors"]
  node_stream_behavior["Stream behaviors"]
  node_prepost["Pre/post processors"]
  node_exception_pipeline["Exception processing"]
end

subgraph group_registration["DI Registration"]
  node_registrar["Assembly registrar"]
  node_di_extensions["DI extensions"]
  node_di_config["Registration config"]
end

subgraph group_licensing["Licensing"]
  node_license_accessor["License accessor<br/>[LicenseAccessor.cs]"]
  node_license_validator["License validator"]
  node_license["License model<br/>[License.cs]"]
end

node_app(("Application code"))

node_app -->|"defines"| node_request_contracts
node_app -->|"defines"| node_stream_contract
node_app -->|"defines"| node_notification_contract
node_app -->|"sends or publishes"| node_mediator
node_mediator -->|"dispatches requests"| node_request_wrapper
node_mediator -->|"dispatches streams"| node_stream_wrapper
node_mediator -->|"dispatches notifications"| node_notification_wrapper
node_request_wrapper -->|"resolves handler"| node_request_handlers
node_request_wrapper -->|"wraps with behaviors"| node_request_behavior
node_stream_wrapper -->|"resolves handler"| node_stream_handlers
node_stream_wrapper -->|"wraps with behaviors"| node_stream_behavior
node_notification_wrapper -->|"creates callbacks"| node_notification_handlers
node_notification_wrapper -->|"creates executors"| node_notification_executor
node_mediator -->|"publishes through"| node_publisher
node_publisher -->|"accepts executors"| node_notification_executor
node_foreach_publisher -->|"implements"| node_publisher
node_parallel_publisher -->|"implements"| node_publisher
node_request_behavior -->|"supports processor behaviors"| node_prepost
node_request_behavior -->|"supports exception behaviors"| node_exception_pipeline
node_app -->|"registers services"| node_di_extensions
node_di_extensions -->|"scans assemblies"| node_registrar
node_di_extensions -->|"uses configuration"| node_di_config
node_di_extensions -->|"resolves for validation"| node_license_accessor
node_di_extensions -->|"validates license"| node_license_validator
node_license_accessor -->|"returns license"| node_license
node_license_validator -->|"validates claims"| node_license

click node_request_contracts "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR.Contracts/IRequest.cs"
click node_stream_contract "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR.Contracts/IStreamRequest.cs"
click node_notification_contract "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR.Contracts/INotification.cs"
click node_mediator "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Mediator.cs"
click node_request_wrapper "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Wrappers/RequestHandlerWrapper.cs"
click node_request_handlers "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/IRequestHandler.cs"
click node_stream_wrapper "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Wrappers/StreamRequestHandlerWrapper.cs"
click node_stream_handlers "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/IStreamRequestHandler.cs"
click node_notification_wrapper "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Wrappers/NotificationHandlerWrapper.cs"
click node_notification_handlers "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/INotificationHandler.cs"
click node_publisher "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/INotificationPublisher.cs"
click node_notification_executor "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/NotificationHandlerExecutor.cs"
click node_foreach_publisher "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/NotificationPublishers/ForeachAwaitPublisher.cs"
click node_parallel_publisher "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/NotificationPublishers/TaskWhenAllPublisher.cs"
click node_request_behavior "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/IPipelineBehavior.cs"
click node_stream_behavior "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/IStreamPipelineBehavior.cs"
click node_prepost "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Pipeline/IRequestPreProcessor.cs"
click node_exception_pipeline "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Pipeline/RequestExceptionProcessorBehavior.cs"
click node_registrar "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Registration/ServiceRegistrar.cs"
click node_di_extensions "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/MicrosoftExtensionsDI/MediatRServiceCollectionExtensions.cs"
click node_di_config "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/MicrosoftExtensionsDI/MediatrServiceConfiguration.cs"
click node_license_accessor "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Licensing/LicenseAccessor.cs"
click node_license_validator "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Licensing/LicenseValidator.cs"
click node_license "https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Licensing/License.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_request_contracts,node_stream_contract,node_notification_contract toneBlue
class node_mediator,node_request_wrapper,node_request_handlers,node_stream_wrapper,node_stream_handlers,node_notification_wrapper,node_notification_handlers,node_publisher,node_notification_executor,node_foreach_publisher,node_parallel_publisher toneAmber
class node_request_behavior,node_stream_behavior,node_prepost,node_exception_pipeline toneMint
class node_registrar,node_di_extensions,node_di_config toneRose
class node_license_accessor,node_license_validator,node_license,node_app toneIndigo
```

## Components

### Contracts

- [Request contracts](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR.Contracts/IRequest.cs): `src/MediatR.Contracts/IRequest.cs`
- [Stream contract](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR.Contracts/IStreamRequest.cs): `src/MediatR.Contracts/IStreamRequest.cs`
- [Notification contract](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR.Contracts/INotification.cs): `src/MediatR.Contracts/INotification.cs`

### Dispatch

- [Mediator](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Mediator.cs): `src/MediatR/Mediator.cs`
- [Request dispatch](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Wrappers/RequestHandlerWrapper.cs): `src/MediatR/Wrappers/RequestHandlerWrapper.cs`
- [Request handlers](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/IRequestHandler.cs): `src/MediatR/IRequestHandler.cs`
- [Stream dispatch](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Wrappers/StreamRequestHandlerWrapper.cs): `src/MediatR/Wrappers/StreamRequestHandlerWrapper.cs`
- [Stream handlers](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/IStreamRequestHandler.cs): `src/MediatR/IStreamRequestHandler.cs`
- [Notification dispatch](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Wrappers/NotificationHandlerWrapper.cs): `src/MediatR/Wrappers/NotificationHandlerWrapper.cs`
- [Notification handlers](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/INotificationHandler.cs): `src/MediatR/INotificationHandler.cs`
- [Notification publisher](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/INotificationPublisher.cs): `src/MediatR/INotificationPublisher.cs`
- [Handler executor](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/NotificationHandlerExecutor.cs): `src/MediatR/NotificationHandlerExecutor.cs`
- [Sequential publisher](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/NotificationPublishers/ForeachAwaitPublisher.cs): `src/MediatR/NotificationPublishers/ForeachAwaitPublisher.cs`
- [Parallel publisher](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/NotificationPublishers/TaskWhenAllPublisher.cs): `src/MediatR/NotificationPublishers/TaskWhenAllPublisher.cs`

### Pipelines

- [Request behaviors](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/IPipelineBehavior.cs): `src/MediatR/IPipelineBehavior.cs`
- [Stream behaviors](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/IStreamPipelineBehavior.cs): `src/MediatR/IStreamPipelineBehavior.cs`
- [Pre/post processors](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Pipeline/IRequestPreProcessor.cs): `src/MediatR/Pipeline/IRequestPreProcessor.cs`
- [Exception processing](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Pipeline/RequestExceptionProcessorBehavior.cs): `src/MediatR/Pipeline/RequestExceptionProcessorBehavior.cs`

### DI Registration

- [Assembly registrar](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Registration/ServiceRegistrar.cs): `src/MediatR/Registration/ServiceRegistrar.cs`
- [DI extensions](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/MicrosoftExtensionsDI/MediatRServiceCollectionExtensions.cs): `src/MediatR/MicrosoftExtensionsDI/MediatRServiceCollectionExtensions.cs`
- [Registration config](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/MicrosoftExtensionsDI/MediatrServiceConfiguration.cs): `src/MediatR/MicrosoftExtensionsDI/MediatrServiceConfiguration.cs`

### Licensing

- [License accessor](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Licensing/LicenseAccessor.cs): `src/MediatR/Licensing/LicenseAccessor.cs`
- [License validator](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Licensing/LicenseValidator.cs): `src/MediatR/Licensing/LicenseValidator.cs`
- [License model](https://github.com/luckypennysoftware/mediatr/blob/main/src/MediatR/Licensing/License.cs): `src/MediatR/Licensing/License.cs`

### Other components

- **Application code**

## Connections

- Application code → Request contracts: defines
- Application code → Stream contract: defines
- Application code → Notification contract: defines
- Application code → Mediator: sends or publishes
- Mediator → Request dispatch: dispatches requests (evidence: `src/MediatR/Mediator.cs`)
- Mediator → Stream dispatch: dispatches streams (evidence: `src/MediatR/Mediator.cs`)
- Mediator → Notification dispatch: dispatches notifications (evidence: `src/MediatR/Mediator.cs`)
- Request dispatch → Request handlers: resolves handler (evidence: `src/MediatR/Wrappers/RequestHandlerWrapper.cs`)
- Request dispatch → Request behaviors: wraps with behaviors (evidence: `src/MediatR/Wrappers/RequestHandlerWrapper.cs`)
- Stream dispatch → Stream handlers: resolves handler (evidence: `src/MediatR/Wrappers/StreamRequestHandlerWrapper.cs`)
- Stream dispatch → Stream behaviors: wraps with behaviors (evidence: `src/MediatR/Wrappers/StreamRequestHandlerWrapper.cs`)
- Notification dispatch → Notification handlers: creates callbacks (evidence: `src/MediatR/Wrappers/NotificationHandlerWrapper.cs`)
- Notification dispatch → Handler executor: creates executors (evidence: `src/MediatR/Wrappers/NotificationHandlerWrapper.cs`)
- Mediator → Notification publisher: publishes through (evidence: `src/MediatR/Mediator.cs`)
- Notification publisher → Handler executor: accepts executors (evidence: `src/MediatR/INotificationPublisher.cs`)
- Sequential publisher → Notification publisher: implements (evidence: `src/MediatR/NotificationPublishers/ForeachAwaitPublisher.cs`)
- Parallel publisher → Notification publisher: implements (evidence: `src/MediatR/NotificationPublishers/TaskWhenAllPublisher.cs`)
- Request behaviors → Pre/post processors: supports processor behaviors (evidence: `src/MediatR/Pipeline/RequestPreProcessorBehavior.cs`)
- Request behaviors → Exception processing: supports exception behaviors (evidence: `src/MediatR/Pipeline/RequestExceptionProcessorBehavior.cs`)
- Application code → DI extensions: registers services
- DI extensions → Assembly registrar: scans assemblies (evidence: `src/MediatR/MicrosoftExtensionsDI/MediatRServiceCollectionExtensions.cs`)
- DI extensions → Registration config: uses configuration (evidence: `src/MediatR/MicrosoftExtensionsDI/MediatRServiceCollectionExtensions.cs`)
- DI extensions → License accessor: resolves for validation (evidence: `src/MediatR/MicrosoftExtensionsDI/MediatRServiceCollectionExtensions.cs`)
- DI extensions → License validator: validates license (evidence: `src/MediatR/MicrosoftExtensionsDI/MediatRServiceCollectionExtensions.cs`)
- License accessor → License model: returns license (evidence: `src/MediatR/Licensing/LicenseAccessor.cs`)
- License validator → License model: validates claims (evidence: `src/MediatR/Licensing/LicenseValidator.cs`)
