Class DerivedTypeClassMapConvention
- Namespace
- Cratis.Arc.MongoDB
- Assembly
- Cratis.Arc.MongoDB.dll
Class map convention that registers the derived-type discriminator convention for every concrete [DerivedType] as its class map is created.
public class DerivedTypeClassMapConvention : ConventionBase, IClassMapConvention, IConvention
- Inheritance
-
ConventionBaseDerivedTypeClassMapConvention
- Implements
-
IClassMapConventionIConvention
- Inherited Members
-
ConventionBase.Name
- Extension Methods
Remarks
The target types (interfaces and base classes) get the convention registered up front, but the driver resolves the discriminator convention per CLASS MAP when delegating from a discriminated interface serializer to the concrete type's serializer — and it passes the original (interface) nominal type along. Without this registration the concrete type's class map falls back to the driver's default "_t" convention, which cannot see the "_derivedTypeId" element and answers with the interface nominal type, bouncing deserialization back to the discriminated interface serializer in an unbounded loop that overflows the stack. Registering the same convention for the concrete types keeps both sides symmetric: writes emit "_derivedTypeId" and the re-check resolves to the type itself, terminating the delegation.
Constructors
DerivedTypeClassMapConvention(IDerivedTypes, IDiscriminatorConvention)
Class map convention that registers the derived-type discriminator convention for every concrete [DerivedType] as its class map is created.
public DerivedTypeClassMapConvention(IDerivedTypes derivedTypes, IDiscriminatorConvention discriminatorConvention)
Parameters
derivedTypesIDerivedTypesThe IDerivedTypes system for knowing which types are derived types.
discriminatorConventionIDiscriminatorConventionThe MongoDB.Bson.Serialization.Conventions.IDiscriminatorConvention to register for derived types.
Remarks
The target types (interfaces and base classes) get the convention registered up front, but the driver resolves the discriminator convention per CLASS MAP when delegating from a discriminated interface serializer to the concrete type's serializer — and it passes the original (interface) nominal type along. Without this registration the concrete type's class map falls back to the driver's default "_t" convention, which cannot see the "_derivedTypeId" element and answers with the interface nominal type, bouncing deserialization back to the discriminated interface serializer in an unbounded loop that overflows the stack. Registering the same convention for the concrete types keeps both sides symmetric: writes emit "_derivedTypeId" and the re-check resolves to the type itself, terminating the delegation.
Methods
Apply(BsonClassMap)
Applies a modification to the class map.
public void Apply(BsonClassMap classMap)
Parameters
classMapBsonClassMapThe class map.