-
Type:
Task
-
Resolution: Done
-
Priority:
Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
The 3 RegisterClassMap methods in BsonClassMap are meant to only be called once for a given type. Normally we expect an application to know whether or not serialization has already been configured or not, but there are potential scenarios where conditional registration might be useful (such as multiple dependencies sharing some common data models where you don't have control over which dependency gets initialized first).
It would be helpful to have a method that can be safely called without knowing in advance whether a class map for a given type has already been registered or not.
This method could be something like:
public void RegisterClassMapIfNotRegistered<TClass>(Action<BconClassMap<TClass>> classMapInitializer)
A possible alternative is to use the `TryXyz` pattern:
public bool TryRegisterClassMap<TClass>(Action<BsonClassMap<TClass>> classMapInitializer, out BsonClassMap<TClass> classMap)
But the question is whether the `bool` return value or the `out classMap` parameter add any usefulness.