[CSHARP-4487] Make BsonClassMap entirely non-static Created: 24/Jan/23 Updated: 09/Jan/24 |
|
| Status: | Backlog |
| Project: | C# Driver |
| Component/s: | Configuration |
| Affects Version/s: | 2.18.0 |
| Fix Version/s: | 3.0.0 |
| Type: | Improvement | Priority: | Unknown |
| Reporter: | Damian Hickey | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Epic Link: | Implement 3.0 release |
| Quarter: | FY24Q3 |
| Documentation Changes Summary: | 1. What would you like to communicate to the user about this feature? |
| Description |
|
BsonClassMap __classMaps is static mutable, with popsicle immutablity. This makes:
Instead, perhaps, add a BsonClassMaps custom collection, move the static methods to there as non-static and allow it to be injected into a MongoClient (vis MongoClientSettings). services.AddBsonClassMaps(map => map.RegisterClassMap<>...); |
| Comments |
| Comment by Damian Hickey [ 10/Mar/23 ] |
|
Hi James Long time no see - you may remember me from PSake days That sounds awesome, I would really like to see that happen. Thanks for fast response and sorry for slow one from me. Cheers! |
| Comment by James Kovacs [ 01/Feb/23 ] |
|
Hi, Damian, Thank you for raising this issue. Although serialization is a separate concern from the lifetime of a MongoClient we plan to address both in CSHARP-3431. We want to scope all resources to the lifetime of a MongoClient including connections, pools, serializers, etc. This would allow users to create two separate MongoClient instances with different configurations for serializing a single class. Right now to achieve this, you have to mirror your class definitions and apply different mapping configurations to each one. This would also make testing the driver much easier as you could dispose of a MongoClient and know that all configuration was cleaned up. You could also test two MongoClient instances in parallel without worrying about automatic serializer configuration from one leaking into the other. Please watch this tickets for updates. Sincerely, |