Class RequestReplyRegistryExtensions
Extension methods for the IRequestReplyRegistry<TRequest> interface.
public static class RequestReplyRegistryExtensions
- Inheritance
-
RequestReplyRegistryExtensions
Examples
RequestReplyRegistryExtensions.RegisterAsync<TRequest, TResponse> simplifies async request-reply handler registration. Instead of the full Func<T, CancellationToken, Task<TResponse>> delegate, you pass a Func<T, Task<TResponse>> and the extension wraps it. The example registers a handler that returns an order status string, exercises the async path, and confirms it was selected over the synchronous overload.
using System;
using System.Threading;
using System.Threading.Tasks;
using Savvyio;
using Savvyio.Handlers;
namespace ExampleApp;
public sealed class RequestReplyRegistryExtensionsExample
{
public bool Register()
{
var registry = new RecordingRequestReplyRegistry();
registry.RegisterAsync<GetOrderQuery, string>(async query =>
{
await Task.CompletedTask;
return "Order " + query.OrderId;
});
return registry.RegisterAsyncCalled;
}
}
public sealed record GetOrderQuery(string OrderId) : Request;
public sealed class RecordingRequestReplyRegistry : IRequestReplyRegistry<IRequest>
{
public bool RegisterAsyncCalled { get; private set; }
public void Register<T, TResponse>(Func<T, TResponse> handler) where T : class, IRequest { }
public void RegisterAsync<T, TResponse>(Func<T, CancellationToken, Task<TResponse>> handler) where T : class, IRequest
{
RegisterAsyncCalled = true;
}
}
Methods
RegisterAsync<TRequest, TResponse>(IRequestReplyRegistry<TRequest>, Func<TRequest, Task<TResponse>>)
Registers the asynchronous.
public static void RegisterAsync<TRequest, TResponse>(this IRequestReplyRegistry<TRequest> registry, Func<TRequest, Task<TResponse>> handler) where TRequest : class
Parameters
registryIRequestReplyRegistry<TRequest>The IRequestReplyRegistry<TRequest> to extend.
handlerFunc<TRequest, Task<TResponse>>The function delegate that handles
TRequest.
Type Parameters
TRequestThe type of the model to store in the registry.
TResponseThe type of the response to return.