Skip to main content

Class ValueObjectIds

Namespace: AdCodicem.ValueObjects.Identifiers
Assembly: AdCodicem.ValueObjects.Identifiers.dll

The clock and the entropy source that New() reads.

public static class ValueObjectIds

Inheritance

objectValueObjectIds

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks

Two layers. sets a process-wide default, which is what an application does once at start-up. opens a scope bound to the current execution flow, which wins over the default for as long as it lives.

The scope is not a convenience: the test suites run in parallel, and a settable static alone would let two tests racing to substitute the clock corrupt one another. The failure that produces is intermittent and lands in whichever test happens to observe it, which is the most expensive kind to diagnose. An scope is bounded by the execution flow, so parallel tests do not interfere and no test collection has to be serialized to stay correct.

Properties

Entropy

Gets the entropy source in effect, preferring the innermost open scope.

public static IdEntropySource Entropy { get; }

Property Value

IdEntropySource

TimeProvider

Gets the clock in effect, preferring the innermost open scope.

public static TimeProvider TimeProvider { get; }

Property Value

TimeProvider

Methods

Configure(TimeProvider?, IdEntropySource?)

Replaces the process-wide default.

public static void Configure(TimeProvider? timeProvider = null, IdEntropySource? entropy = null)

Parameters

timeProvider TimeProvider?

Clock to use, or null to keep the current one.

entropy IdEntropySource?

Entropy source to use, or null to keep the current one.

Remarks

Intended to be called once, during start-up, before anything generates an identifier. It is not synchronized against concurrent generation: substituting the clock while requests are in flight is a test concern, and is the member for that.

Use(TimeProvider?, IdEntropySource?)

Opens a scope that overrides the default for the current execution flow.

public static IDisposable Use(TimeProvider? timeProvider = null, IdEntropySource? entropy = null)

Parameters

timeProvider TimeProvider?

Clock to use, or null to inherit the enclosing one.

entropy IdEntropySource?

Entropy source to use, or null to inherit the enclosing one.

Returns

IDisposable

A handle that restores the enclosing state when disposed.

Examples

using (ValueObjectIds.Use(fakeClock, deterministicBytes))
{
var id = AccountId.New();
}