Table of Contents

MetadataExtensions Class

Definition

Namespace
Savvyio
Assemblies
Savvyio.Core.dll
Source
src/Savvyio.Core/MetadataExtensions.cs

Extension methods for the IMetadata interface.

public static class MetadataExtensions
Inheritance
MetadataExtensions

Examples

This example shows how a request can collect reserved metadata, merge values from an upstream request, and read the normalized values back again. The workflow exercises the metadata helpers that are typically used by command, event, and integration-message pipelines.

using System;
using Savvyio;

namespace ExampleApp;

public sealed class MetadataExtensionsExample
{
    public (string CorrelationId, string MemberType, string Tenant) Enrich()
    {
        var parent = new CreateOrderCommand("ORD-41").SetCorrelationId("corr-41").SaveMetadata("tenant", "eu-west");
        var command = new CreateOrderCommand("ORD-42")
            .SetCorrelationId("corr-42")
            .SetCausationId("checkout")
            .SetRequestId("req-42")
            .SetEventId("evt-42")
            .SetMemberType(typeof(CreateOrderCommand))
            .SetTimestamp(new DateTime(2026, 7, 1, 0, 0, 0, DateTimeKind.Utc))
            .MergeMetadata(parent);

        var correlationId = command.GetCorrelationId();
        var causationId = command.GetCausationId();
        var requestId = command.GetRequestId();
        var memberType = command.GetMemberType();
        return (correlationId, memberType, (string)command.Metadata["tenant"]);
    }
}

public sealed record CreateOrderCommand(string OrderId) : Request;

Methods

Name Description
GetCausationId<T>(T)

Gets the string representation of the causation identifier from the request.

GetCorrelationId<T>(T)

Gets the string representation of the correlation identifier from the request.

GetMemberType<T>(T)

Gets the string representation of the underlying member type of request.

GetRequestId<T>(T)

Gets the string representation of the request identifier from the request.

MergeMetadata<TSource, TDestination>(TDestination, TSource)

Copies model from the source to the destination if not already existing.

SaveMetadata<T>(T, string, object)

Add or update a set of model to the request.

SetCausationId<T>(T, string)

Assigns a new causationId to the request.

SetCorrelationId<T>(T, string)

Assigns a new correlationId to the request.

SetEventId<T>(T, string)

Assigns a new eventId to the request.

SetMemberType<T>(T, Type)

Assigns a new type to the request.

SetRequestId<T>(T, string)

Assigns a new requestId to the request.

SetTimestamp<T>(T, DateTime?)

Assigns a new timestamp (UtcNow value) to the request.