DispatchCore 1.0.1
dotnet add package DispatchCore --version 1.0.1
NuGet\Install-Package DispatchCore -Version 1.0.1
<PackageReference Include="DispatchCore" Version="1.0.1" />
<PackageVersion Include="DispatchCore" Version="1.0.1" />
<PackageReference Include="DispatchCore" />
paket add DispatchCore --version 1.0.1
#r "nuget: DispatchCore, 1.0.1"
#:package DispatchCore@1.0.1
#addin nuget:?package=DispatchCore&version=1.0.1
#tool nuget:?package=DispatchCore&version=1.0.1
DispatchCore
A lightweight mediator implementation for .NET applications.
DispatchCore provides a simple and extensible way to decouple requests from their handlers while supporting CQRS-oriented and Clean Architecture applications.
It integrates seamlessly with the .NET dependency injection system and automatically registers request handlers through assembly scanning.
Features
- Request/response handling
- Automatic handler registration
- Assembly scanning
- Native .NET dependency injection integration
- Lightweight and easy to configure
- Designed for CQRS and Clean Architecture applications
Requirements
- .NET 8.0 or later
Installation
Install the latest version of DispatchCore using the .NET CLI:
dotnet add package DispatchCore
Or using the Package Manager Console:
Install-Package DispatchCore
Configuration
Create a DependencyInjection class in your Core or Application project.
public static class DependencyInjection
{
public static IServiceCollection AddApplicationCore(
this IServiceCollection services)
{
var assembly = typeof(DependencyInjection).Assembly;
services.AddDispatchCore(assembly);
return services;
}
}
The assembly containing the DependencyInjection class is automatically scanned to register request handlers.
Then register your application services in Program.cs:
builder.Services.AddApplicationCore();
Requests and Handlers
Define a request:
public class GetUserQuery : IRequest<UserDto>
{
public int UserId { get; set; }
}
Create the corresponding handler:
public class GetUserQueryHandler
: IRequestHandler<GetUserQuery, UserDto>
{
public async Task<UserDto> Handle(
GetUserQuery request,
CancellationToken cancellationToken)
{
// Application logic
return new UserDto();
}
}
Sending Requests
Inject IMediator into your service or controller:
public class UsersController : ControllerBase
{
private readonly IMediator _mediator;
public UsersController(IMediator mediator)
{
_mediator = mediator;
}
[HttpGet("{id}")]
public async Task<IActionResult> Get(int id)
{
var query = new GetUserQuery
{
UserId = id
};
var result = await _mediator.Send(query);
return Ok(result);
}
}
Assembly Scanning
DispatchCore automatically scans the specified assembly and registers the available request handlers.
services.AddDispatchCore(assembly);
This allows handlers to be registered automatically without manually registering each handler in the dependency injection container.
Clean Architecture and CQRS
DispatchCore is designed to work seamlessly with Clean Architecture and CQRS-based applications.
A typical application structure could look like this:
Application
├── Features
│ ├── Users
│ │ ├── GetUserQuery.cs
│ │ └── GetUserQueryHandler.cs
│ └── Orders
│ ├── CreateOrderCommand.cs
│ └── CreateOrderCommandHandler.cs
└── DependencyInjection.cs
Why DispatchCore?
DispatchCore is designed to keep mediator-based architectures simple and lightweight.
It provides the core functionality required to decouple requests from their handlers while keeping the application architecture clean and easy to maintain.
DispatchCore is a suitable choice for applications that need a simple mediator implementation without unnecessary complexity.
License
This project is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- FluentValidation (>= 12.1.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.