Aligator 1.2.0
dotnet add package Aligator --version 1.2.0
NuGet\Install-Package Aligator -Version 1.2.0
<PackageReference Include="Aligator" Version="1.2.0" />
<PackageVersion Include="Aligator" Version="1.2.0" />
<PackageReference Include="Aligator" />
paket add Aligator --version 1.2.0
#r "nuget: Aligator, 1.2.0"
#:package Aligator@1.2.0
#addin nuget:?package=Aligator&version=1.2.0
#tool nuget:?package=Aligator&version=1.2.0
<img src="https://raw.githubusercontent.com/ali-golshani/Aligator/refs/heads/main/Aligator.jpg" alt="My Image" width="200" height="300">
Mediator with Custom Pipelines
This mediator enables the definition of different pipelines for various request types, allowing for greater flexibility and control.
Usage
Define a marker interface or base class for each pipeline requests
public interface IRequestA { }
Define requests and request handlers
public sealed class Ping : IRequest<Ping, string>, IRequestA
{
// Implementation details
}
public sealed class PingHandler : IRequestHandler<Ping, string>
{
public Task<string> Handle(Ping request, CancellationToken cancellationToken)
{
// ...
}
}
The TRequest generic parameter in the IRequest interface is designed to eliminate the need for C# reflection in the implementation of the Mediator class. This approach ensures type safety and significantly reduces the runtime overhead commonly associated with reflection-based solutions.
Define middlewares
Custom middleware can be created to process general or specific request types. C#'s generic type constraints (where keyword) can be used to enforce type restrictions.
public sealed class ExceptionHandlingMiddleware<TRequest, TResponse> : IMiddleware<TRequest, TResponse>
{
public async Task<TResponse> Handle(RequestContext<TRequest> context, IRequestProcessor<TRequest, TResponse> next)
{
try
{
return await next.Handle(context);
}
catch (Exception exp)
{
// Exception handling logic
}
}
}
public sealed class SpecialMiddleware<TRequest, TResponse> : IMiddleware<TRequest, TResponse>
where TRequest : ISpecialRequest
{
// Middleware implementation
}
Define pipelines
Define pipelines by using the KeyedPipeline base class.
This approach involves defining a uniquely named pipeline class along with a configuration class that implements the IKeyedPipelineConfiguration interface.
internal sealed class PipelineA<TRequest, TResponse> : KeyedPipeline<TRequest, TResponse>
where TRequest : IRequest<TRequest, TResponse>, IRequestA
{
public PipelineA(IServiceProvider serviceProvider)
: base(serviceProvider, PipelineAConfiguration.PipelineName)
{ }
}
internal sealed class PipelineAConfiguration : IKeyedPipelineConfiguration
{
public static string PipelineName { get; } = "Pipeline_A";
public static Type[] Middlewares()
{
return
[
typeof(ExceptionHandlingMiddleware<,>),
typeof(ValidationMiddleware<,>),
typeof(SpecialMiddleware<,>),
];
}
}
Register the pipeline in DI:
services.AddScoped(typeof(IPipeline<,>), typeof(PipelineA<,>));
services.AddMiddlewares<PipelineAConfiguration>();
Use IMediator to handle requests
private static async Task Sample(IMediator mediator, CancellationToken cancellationToken)
{
var request = new Ping() { /* ... */ };
var response = await mediator.Send(request, cancellationToken);
// ...
}
| 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 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 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
-
net9.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|