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.
Methods
GenerateId(object, object)
Mints a new identifier, through
public object GenerateId(object container, object document)
Parameters
container object
The collection the document is inserted into.
document object
The document.
Returns
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
true when the document needs a new identifier.