Class ValueObjectBson
Namespace: AdCodicem.ValueObjects.MongoDB
Assembly: AdCodicem.ValueObjects.MongoDB.dll
Registers the MongoDB.Driver serializers of value objects.
public static class ValueObjectBson
Inheritance
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
MongoDB.Driver keeps its serializers in a process-wide registry that never forgets one, and maps a type it has no
serializer for through a class map. A value object has no member a class map can set, so without these serializers it
is written as an empty sub-document, {}, read back as its default instance, and a query over it compares
{}, matching every document or none. Call
Methods
Register(params Assembly[])
Registers, once, the provider that hands the driver a strict serializer for every value object.
[RequiresUnreferencedCode("Locates the generated registration of each assembly given by its metadata.")]
public static void Register(params Assembly[] assemblies)
Parameters
assemblies Assembly[]
Assemblies declaring value objects, whose generated registration runs first, so that their value objects are checked.
Remarks
Strict, as trusted: false is: every value read goes through
the value object's rules, since a collection has no schema and is often written by other services, scripts or
tools.
Exceptions
assemblies is null.
The provider is already registered with trusted: true; a value object over
Register(bool, params Assembly[])
Registers, once, the provider that hands the driver a serializer for every value object, trusted or strict.
[RequiresUnreferencedCode("Locates the generated registration of each assembly given by its metadata.")]
public static void Register(bool trusted, params Assembly[] assemblies)
Parameters
trusted bool
Whether reads skip validation, through CreateUnchecked, for a collection the application alone writes;
false reads through TryCreate, and refuses a value the value object rejects.
assemblies Assembly[]
Assemblies declaring value objects, whose generated registration runs first, so that their value objects are checked.
Remarks
The provider answers every value object the driver meets, whichever assembly declares it, with a
Two mistakes are refused here rather than on the first document. A value object over new GuidSerializer(GuidRepresentation.Standard) before calling this method. And a value object the
driver has already serialized, before this call, keeps the class map it was given, which writes {}, for the
rest of the process: the exception names the value objects concerned, and the registration has to move before
whatever serialized them, a construction of a generic value object and a value object written by hand included.
The
A value object over
A construction of a generic value object, a value object written by hand, or one in an assembly whose registration
has not run, that nothing registered, is described by reflection the first time the driver asks for it
(
Exceptions
assemblies is null.
The provider is already registered with the other trust; a value object over
Register<TSelf, TValue>(bool)
Registers the serializer of one value object, such as a construction of a generic value object.
public static void Register<TSelf, TValue>(bool trusted = false) where TSelf : struct, IValueObject<TSelf, TValue>
Parameters
trusted bool
Whether reads skip validation, for a collection the application alone writes; false, the default, reads through the value object's rules.
Type Parameters
TSelf
Value object type, Code<Order> for instance.
TValue
Underlying value type.
Remarks
The serializer is the one
Exceptions
TValue is
TValue is
BsonSerializationException
The driver already holds a different serializer for TSelf: one of the other trust, one of
the application's own, or the class map it gave a value object it serialized before any registration.