Table of Contents

SavvyioOptionsExtensions Class

Definition

Namespace
Savvyio.Queries
Assemblies
Savvyio.Queries.dll
Source
src/Savvyio.Queries/SavvyioOptionsExtensions.cs

Extension methods for the SavvyioOptions class.

public static class SavvyioOptionsExtensions
Inheritance
SavvyioOptionsExtensions

Examples

This example shows how to configure SavvyioOptions for a query-driven application service. The options register both the query handler implementation and the default query dispatcher so request-reply operations can resolve through the same configuration object.

using Savvyio;
using Savvyio.Handlers;
using Savvyio.Queries;

namespace ExampleApp;

public sealed class QueryOptionsExtensionsExample
{
    public int Configure()
    {
        var options = new SavvyioOptions().AddQueryHandler<GetOrderTotalHandler>().AddQueryDispatcher();
        return options.HandlerImplementationTypes.Count + options.DispatcherImplementationTypes.Count;
    }
}

public sealed class GetOrderTotalHandler : IQueryHandler
{
    public IRequestReplyActivator<IQuery> Delegates => HandlerFactory.CreateRequestReply<IQuery>(registry => registry.Register<GetOrderTotalQuery, decimal>(_ => 42m));
}

public sealed record GetOrderTotalQuery(string OrderId) : Request, IQuery<decimal>;

Methods

Name Description
AddQueryDispatcher(SavvyioOptions)

Adds a default implementation of the IQueryDispatcher interface.

AddQueryHandler<TImplementation>(SavvyioOptions)

Adds an implementation of the IQueryHandler interface to HandlerImplementationTypes (if not already registered).