Skip to main content
Version: 0.3.x (0.3.0)

Class EntityIdGenerator<TId>

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

Mints an entity identifier for a document inserted without one, as MongoDB.Driver mints an ObjectId.

public sealed class EntityIdGenerator<TId> : IIdGenerator where TId : struct, IEntityId<TId>

Type Parameters​

TId

The identifier type.

Inheritance​

object ← EntityIdGenerator<TId>

Implements​

IIdGenerator

Inherited Members​

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

Remarks​

The driver asks the generator of a document's id member, before it serializes the document, whether the id is still unassigned, and has it mint one if so. An unassigned identifier is the default instance, which holds no valid value: without a generator, the serializer of AdCodicem.ValueObjects.MongoDB would refuse to write it, with value_object.required.

registers one per identifier type, which the driver's class maps take up when they are built; a class map built by hand sets it with .

Methods​

GenerateId(object, object)​

Mints a new identifier, through , under the clock and the entropy holds for the current flow.

public object GenerateId(object container, object document)

Parameters​

container object

The collection the document is inserted into.

document object

The document.

Returns​

object

The new identifier, boxed.

IsEmpty(object?)​

Tells an unassigned identifier: the default instance, or anything that is not an identifier of the type.

public bool IsEmpty(object? id)

Parameters​

id object?

The value of the document's id member.

Returns​

bool

true when the document needs a new identifier.