LfrlAnvil.Requests 0.2.1

dotnet add package LfrlAnvil.Requests --version 0.2.1
NuGet\Install-Package LfrlAnvil.Requests -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="LfrlAnvil.Requests" Version="0.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LfrlAnvil.Requests --version 0.2.1
#r "nuget: LfrlAnvil.Requests, 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.
// Install LfrlAnvil.Requests as a Cake Addin
#addin nuget:?package=LfrlAnvil.Requests&version=0.2.1

// Install LfrlAnvil.Requests as a Cake Tool
#tool nuget:?package=LfrlAnvil.Requests&version=0.2.1

(root) NuGet Badge

LfrlAnvil.Requests

This project contains an intermediate request dispatcher, as well as a factory of request handlers.

Documentation

Technical documentation can be found here.

Examples

Following is an example of how to define a request type, how to create a handler of such requests and how to dispatch a request:

// a class that defines a request,
// with int as the type of the request's result
public class FooRequest : IRequest<FooRequest, int>
{
    // request members
}

// a class that represents a handler of requests of FooRequest type,
// with int as the type of the request's result
public class FooRequestHandler : IRequestHandler<FooRequest, int>
{
    // request handling implementation
    public int Handle(FooRequest request)
    {
        // implementation goes here
        return result;
    }
}

// creates a new empty factory of request handlers, identified by request type,
// with registered FooRequest handler
var handlerFactory = new RequestHandlerFactory()
    .Register( () => new FooRequestHandler() );

// creates a new request dispatcher that uses the above request handler factory instance
var dispatcher = new RequestDispatcher( handlerFactory );

// creates a new FooRequest instance
var request = new FooRequest { ... };

// dispatches the request and returns the result returned by its handler
var result = dispatcher.Dispatch( request );

It's also possible to work with asynchronous requests, like so:

// a class that defines an asynchronous request,
// with int as the type of the request's result
public class AsyncFooRequest : IAsyncTaskRequest<AsyncFooRequest, int>
{
    // request's cancellation token
    public CancellationToken CancellationToken { get; init; }
    
    // other request members
}

// a class that represents a handler of requests of AsyncFooRequest type,
// with int as the type of the request's result
public class AsyncFooRequestHandler : IRequestHandler<AsyncFooRequest, Task<int>>
{
    // request handling implementation
    public Task<int> Handle(AsyncFooRequest request)
    {
        // implementation goes here
        return result;
    }
}

// creates a new empty factory of request handlers, identified by request type,
// with registered AsyncFooRequest handler
var handlerFactory = new RequestHandlerFactory()
    .Register( () => new AsyncFooRequestHandler() );

// creates a new request dispatcher that uses the above request handler factory instance
var dispatcher = new RequestDispatcher( handlerFactory );

// creates a new AsyncFooRequest instance
var cancellationTokenSource = new CancellationTokenSource();
var request = new AsyncFooRequest { CancellationToken = cancellationTokenSource.Token, ... };

// dispatches the request and returns the result returned by its handler
var result = await dispatcher.Dispatch( request );
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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

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
0.2.1 69 6/16/2024
0.2.0 64 6/16/2024
0.1.1 63 5/29/2024
0.1.0 76 5/26/2024