IronAlpine.Mediator.DependencyInjection
0.2.1
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package IronAlpine.Mediator.DependencyInjection --version 0.2.1
NuGet\Install-Package IronAlpine.Mediator.DependencyInjection -Version 0.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IronAlpine.Mediator.DependencyInjection" Version="0.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IronAlpine.Mediator.DependencyInjection" Version="0.2.1" />
<PackageReference Include="IronAlpine.Mediator.DependencyInjection" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IronAlpine.Mediator.DependencyInjection --version 0.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: IronAlpine.Mediator.DependencyInjection, 0.2.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package IronAlpine.Mediator.DependencyInjection@0.2.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IronAlpine.Mediator.DependencyInjection&version=0.2.1
#tool nuget:?package=IronAlpine.Mediator.DependencyInjection&version=0.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
IronAlpine Mediator
IronAlpine.Mediator is a lightweight mediator stack for .NET applications.
Packages
IronAlpine.Mediator.Abstractions
- Contracts for requests, notifications, stream requests, and pipeline behaviors.
IronAlpine.Mediator
- Runtime implementation for dispatching request/response, notifications, and streams.
IronAlpine.Mediator.DependencyInjection
IServiceCollectionintegration with assembly scanning and open behavior registration.
Target Frameworks
- .NET 9
- .NET 10
Installation
Typical application usage:
dotnet add package IronAlpine.Mediator.DependencyInjection
Contracts-only usage:
dotnet add package IronAlpine.Mediator.Abstractions
Custom runtime wiring:
dotnet add package IronAlpine.Mediator
dotnet add package IronAlpine.Mediator.Abstractions
Request/Response
using IronAlpine.Mediator.Abstractions.Contracts;
public sealed record GetUserQuery(Guid UserId) : IRequest<UserDto>;
public sealed class GetUserQueryHandler : IRequestHandler<GetUserQuery, UserDto>
{
public Task<UserDto> Handle(GetUserQuery request, CancellationToken cancellationToken)
=> Task.FromResult(new UserDto(request.UserId, "demo.user"));
}
public sealed record UserDto(Guid Id, string Username);
Registration
using IronAlpine.Mediator.DependencyInjection.Extensions;
builder.Services.AddIronAlpineMediator(cfg =>
{
cfg.RegisterServicesFromAssemblyContaining<GetUserQueryHandler>();
});
Usage
using IronAlpine.Mediator.Abstractions.Contracts;
public sealed class UserService
{
private readonly IMediator _mediator;
public UserService(IMediator mediator)
{
_mediator = mediator;
}
public Task<UserDto> GetUserAsync(Guid id, CancellationToken ct)
=> _mediator.Send(new GetUserQuery(id), ct);
}
Notifications
using IronAlpine.Mediator.Abstractions.Contracts;
public sealed record UserCreated(Guid UserId) : INotification;
public sealed class AuditHandler : INotificationHandler<UserCreated>
{
public Task Handle(UserCreated notification, CancellationToken cancellationToken)
=> Task.CompletedTask;
}
Configure publish strategy:
using IronAlpine.Mediator.Abstractions.Contracts;
using IronAlpine.Mediator.DependencyInjection.Extensions;
builder.Services.AddIronAlpineMediator(cfg =>
{
cfg.RegisterServicesFromAssemblyContaining<AuditHandler>();
cfg.UseNotificationPublishStrategy(NotificationPublishStrategy.Sequential);
});
Pipeline Behaviors
using IronAlpine.Mediator.Abstractions.Contracts;
public sealed class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
public async Task<TResponse> Handle(
TRequest request,
RequestHandlerDelegate<TResponse> next,
CancellationToken cancellationToken)
{
return await next();
}
}
Register open behavior:
builder.Services.AddIronAlpineMediator(cfg =>
{
cfg.RegisterServicesFromAssemblyContaining<GetUserQueryHandler>();
cfg.AddOpenBehavior(typeof(LoggingBehavior<,>));
});
Streaming
using System.Runtime.CompilerServices;
using IronAlpine.Mediator.Abstractions.Contracts;
public sealed record StreamUsersQuery() : IStreamRequest<UserDto>;
public sealed class StreamUsersQueryHandler : IStreamRequestHandler<StreamUsersQuery, UserDto>
{
public async IAsyncEnumerable<UserDto> Handle(
StreamUsersQuery request,
[EnumeratorCancellation] CancellationToken cancellationToken)
{
yield return new UserDto(Guid.NewGuid(), "user-1");
yield return new UserDto(Guid.NewGuid(), "user-2");
await Task.CompletedTask;
}
}
Consume stream:
await foreach (var item in mediator.CreateStream(new StreamUsersQuery(), ct))
{
// process item
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- IronAlpine.Mediator (>= 0.2.1)
- IronAlpine.Mediator.Abstractions (>= 0.2.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
-
net9.0
- IronAlpine.Mediator (>= 0.2.1)
- IronAlpine.Mediator.Abstractions (>= 0.2.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Stable patch release: DI registration hardening and compatibility alignment.