QueryDispatcher Class
Definition
Provides a default implementation of of the IQueryDispatcher interface.
public class QueryDispatcher : RequestReplyDispatcher, IQueryDispatcher, IDispatcher
- Inheritance
-
QueryDispatcher
- Implements
- Inherited Members
Examples
This example shows how to route a request-reply query through the built-in query dispatcher. The handler returns a computed order total, which gives the caller an observable outcome from the dispatcher workflow.
using Savvyio;
using Savvyio.Dispatchers;
using Savvyio.Handlers;
using Savvyio.Queries;
namespace ExampleApp;
public sealed class QueryDispatcherExample
{
public decimal Query()
{
var handler = new GetOrderTotalHandler();
var dispatcher = new QueryDispatcher(new ServiceLocator(serviceType => serviceType == typeof(IQueryHandler) ? new object[] { handler } : []));
return dispatcher.Query(new GetOrderTotalQuery("ORD-42"));
}
}
public sealed class GetOrderTotalHandler : IQueryHandler
{
public IRequestReplyActivator<IQuery> Delegates => HandlerFactory.CreateRequestReply<IQuery>(registry => registry.Register<GetOrderTotalQuery, decimal>(query => query.OrderId.Length * 10m));
}
public sealed record GetOrderTotalQuery(string OrderId) : Request, IQuery<decimal>;
Constructors
| Name | Description |
|---|---|
| QueryDispatcher(IServiceLocator) | Initializes a new instance of the QueryDispatcher class. |
Methods
| Name | Description |
|---|---|
| QueryAsync<TResult>(IQuery<TResult>, Action<AsyncOptions>) | Queries the specified |
| Query<TResult>(IQuery<TResult>) | Queries the specified |