Table of Contents

Class MetadataFactory

Namespace
Savvyio
Assembly
Savvyio.Core.dll

Provides access to factory methods for maintaining metadata in models.

public static class MetadataFactory
Inheritance
MetadataFactory

Examples

This example shows how to persist a custom metadata value on a request and retrieve it later in the pipeline.

using Savvyio;

namespace ExampleApp;

public sealed class MetadataFactoryExample
{
    public string GetTenant()
    {
        var command = new CreateOrderCommand("ORD-42");
        MetadataFactory.Set(command, "tenant", "eu-west");
        return (string)MetadataFactory.Get(command, "tenant");
    }
}

public sealed record CreateOrderCommand(string OrderId) : Request;

Methods

Get<T>(T, string)

Gets the value associates to the request from the item with the specified key.

public static object Get<T>(T request, string key) where T : IMetadata

Parameters

request T

The IMetadata to extend.

key string

The key of the element to retrieve.

Returns

object

A reference to the value in the request that is identified by key, if the entry exists; otherwise, null.

Type Parameters

T

The model that implements the IMetadata interface.

Set<T>(T, string, object)

Assigns a new value to the request on the item with the specified key.

public static T Set<T>(T request, string key, object value) where T : IMetadata

Parameters

request T

The IMetadata to extend.

key string

The key of the element to retrieve.

value object

The value of the element to change.

Returns

T

A reference to request after the operation has completed.

Type Parameters

T

The model that implements the IMetadata interface.

Exceptions

ArgumentNullException

request cannot be null -or- key cannot be null.