Table of Contents

CommandExtensions Class

Definition

Namespace
Savvyio.Commands.Messaging
Assemblies
Savvyio.Commands.Messaging.dll
Source
src/Savvyio.Commands.Messaging/CommandExtensions.cs

Extension methods for the ICommand interface.

public static class CommandExtensions
Inheritance
CommandExtensions

Examples

The following example shows how to wrap a command in a transport-ready Message<T> by calling ToMessage.

using System;
using Savvyio.Commands;
using Savvyio.Commands.Messaging;
using Savvyio.Messaging;

namespace ExampleApp.CommandMessages;

public sealed class CommandExtensionsUsage
{
    public CommandExtensionsUsage()
    {
        var command = new CreateInvoiceCommandMessage("INV-42");
        IMessage<CreateInvoiceCommandMessage> message = command.ToMessage(
            new Uri("https://api.example.com/commands/invoices"),
            nameof(CreateInvoiceCommandMessage),
            options => options.MessageId = "msg-invoice-42");

        MessageId = message.Id;
        Type = message.Type;
        Source = message.Source;
    }

    public string MessageId { get; }

    public string Type { get; }

    public string Source { get; }
}

public sealed record CreateInvoiceCommandMessage(string InvoiceId) : Command;

Methods

Name Description
ToMessage<T>(T, Uri, string, Action<MessageOptions>)

Encloses the specified command to an instance of Message<T>.