Aligator 1.2.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Aligator --version 1.2.0
                    
NuGet\Install-Package Aligator -Version 1.2.0
                    
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="Aligator" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aligator" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Aligator" />
                    
Project file
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 Aligator --version 1.2.0
                    
#r "nuget: Aligator, 1.2.0"
                    
#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 Aligator@1.2.0
                    
#: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=Aligator&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Aligator&version=1.2.0
                    
Install as a Cake Tool

<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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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