-
Notifications
You must be signed in to change notification settings - Fork 0
Core Concepts
Mediatron is built around a few simple ideas. Understanding them makes the rest of the wiki easy to follow.
Instead of your controllers or services calling business logic classes directly, they send a message to a mediator. The mediator finds the correct handler and runs it. This keeps your code decoupled — the sender does not need to know which class handles the work.
Mediatron splits your operations into two kinds of "requests":
-
Commands — actions that change data (e.g.,
CreateProductCommand). -
Queries — actions that read data (e.g.,
GetProductByIdQuery).
Both are modeled with the same IRequest / IRequest<TResponse> interfaces, so you can send them the same way.
Sometimes one action should trigger multiple side effects — for example, sending an email and logging an event when a product is created. Mediatron supports this with INotification and INotificationHandler<T>. One notification can have many handlers, and they all run when the notification is published.
A Pipeline Behavior wraps around a request handler, so you can run code before and after it runs — without touching the handler itself. This is useful for cross-cutting concerns like logging, timing, or validation. Behaviors are set up with IPipelineBehavior<TRequest> or IPipelineBehavior<TRequest, TResponse>, and Mediatron registers them automatically, just like handlers.
| Concept | Purpose |
|---|---|
IRequest / IRequest<TResponse>
|
Marks a class as a command or query. |
IRequestHandler<TRequest, TResponse> |
Contains the logic that handles a request. |
INotification |
Marks a class as an event. |
INotificationHandler<TNotification> |
Contains the logic that reacts to an event. |
IPipelineBehavior<TRequest> / IPipelineBehavior<TRequest, TResponse>
|
Wraps logic (e.g., logging, validation) around a request handler. |
IMediator |
The main entry point used to send requests and publish notifications. |
See Requests and Handlers (CQRS), Notifications (Pub/Sub), and Pipeline Behaviors for full examples.