[CSHARP-584] Improve the design of the convention system for automapping BsonClassMaps Created: 29/Sep/12  Updated: 20/Mar/14  Resolved: 19/Dec/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.7, 2.0
Fix Version/s: 1.8

Type: Improvement Priority: Major - P3
Reporter: Robert Stam Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CSHARP-569 BsonId attribute does not opt-in the ... Closed
Duplicate
is duplicated by CSHARP-512 Improve conventions to make them more... Closed
Backwards Compatibility: Minor Change

 Description   

In 1.6, the design of the convention system for automapping BsonClassMaps is fixed and can't be extended. For 2.0, we are redesigning the convention system to be much more flexible and extensible. See the following new interfaces and classes for details:

IConvention
IConventionPack
IClassMapConvention
IMemberMapConvention
IPostProcessingConvention

ConventionPack
ConventionRegistry

The general idea is that ConventionPacks are registered with a filter lambda that determines which types the ConventionPack applies to. When it comes time to AutoMap a class, all the matching ConventionPacks from the registry are combined to produce an effective ConventionPack for that class. The effective ConventionPack may include multiple conventions for the same thing (if more than one matched), but the last one added is the last one to run and wins.

If you wish to write your own custom conventions, you would implement one or more of the convention interfaces: IClassMapConvention, IMemberMapConvention and IPostProcessingConvention, put them in a ConventionPack and register the pack.

AutoMap runs all the IClassMapConventions first, then all the IMemberMapConventions (on whatever members were added to the class map during the first phase), and finally all IPostProcessingConventions to do any final processing of the class map.

This change has no effect on the attribute based configuration of class maps or the fluent interface used to configure class maps via code.. However, it will be backwards breaking for 2 groups of people.
1) Those who wrote a custom convention. They will need to change their convention to match the new api, which should be relatively trivial.
2) Those who have registered a custom convention. They will need to register their convention in a slightly different manner, which is also relatively trivial.



 Comments   
Comment by auto [ 24/Dec/12 ]

Author:

{u'date': u'2012-12-24T23:09:31Z', u'email': u'craiggwilson@gmail.com', u'name': u'Craig Wilson'}

Message: CSHARP-584: rewrote convention system to be more flexible and more predictable.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/93b2f6e853732d56bf80ad952def72b09f29130e

Comment by Craig Wilson [ 19/Dec/12 ]

In code review.

Comment by Robert Stam [ 29/Nov/12 ]

Reopened to backport to 1.8.

For 1.8 the existing convention classes will be deprecated, but will still be supported by some form of interoperation with the new architecture.

Comment by auto [ 09/Oct/12 ]

Author:

{u'date': u'2012-10-08T14:13:59-07:00', u'email': u'craiggwilson@gmail.com', u'name': u'Craig Wilson'}

Message: CSHARP-584: code review comments.
Branch: x2.0
https://github.com/mongodb/mongo-csharp-driver/commit/407e75421fdf9be87b58a747ef2fd46c683fd796

Comment by auto [ 09/Oct/12 ]

Author:

{u'date': u'2012-10-05T08:26:28-07:00', u'email': u'craiggwilson@gmail.com', u'name': u'Craig Wilson'}

Message: CSHARP-584: added support for disallowing an IBsonMemberMapAttribute from applying to more than one member.
Branch: x2.0
https://github.com/mongodb/mongo-csharp-driver/commit/df343382ba526867616c82069bc6e2da5ec0330e

Comment by auto [ 05/Oct/12 ]

Author:

{u'date': u'2012-10-05T06:03:28-07:00', u'email': u'craiggwilson@gmail.com', u'name': u'Craig Wilson'}

Message: CSHARP-584: added IgnoreIfDefault, IgnoreIfNull, and IgnoreExtraElements convention tests.
Branch: x2.0
https://github.com/mongodb/mongo-csharp-driver/commit/cbb0b079819309c2f274160a7da0f2bba1a494a8

Comment by auto [ 05/Oct/12 ]

Author:

{u'date': u'2012-10-05T05:56:04-07:00', u'email': u'craiggwilson@gmail.com', u'name': u'Craig Wilson'}

Message: CSHARP-584: added Conventions property back to BsonClassMap.
Branch: x2.0
https://github.com/mongodb/mongo-csharp-driver/commit/1301b6b1d0d0096e30eb8654da31aa3293a49101

Comment by auto [ 05/Oct/12 ]

Author:

{u'date': u'2012-10-05T05:54:19-07:00', u'email': u'craiggwilson@gmail.com', u'name': u'Craig Wilson'}

Message: CSHARP-584: added tests for the Reset methods in BsonClassMap and BsonMemberMap.
Branch: x2.0
https://github.com/mongodb/mongo-csharp-driver/commit/89aa2a50340403dd4fe54a545c1368764feee0c4

Comment by auto [ 05/Oct/12 ]

Author:

{u'date': u'2012-10-01T19:08:36-07:00', u'email': u'robert@10gen.com', u'name': u'rstam'}

Message: CSHARP-584: Combined Always and Never conventions and added Reset conventions.
Branch: x2.0
https://github.com/mongodb/mongo-csharp-driver/commit/bea7532e924420c4afaecd299d2335c519eaa8fd

Comment by auto [ 01/Oct/12 ]

Author:

{u'date': u'2012-09-30T20:01:21-07:00', u'email': u'robert@10gen.com', u'name': u'rstam'}

Message: CSHARP-584: replaced TypeRepresentationSerializationOptionsConvention with the more general MemberSerializationOptionsConvention. Added a MemberDefaultValueConvention.
Branch: x2.0
https://github.com/mongodb/mongo-csharp-driver/commit/571d50f6b408b835f36903aa963ed58667aec164

Comment by auto [ 30/Sep/12 ]

Author:

{u'date': u'2012-09-29T20:21:11-07:00', u'email': u'robert@10gen.com', u'name': u'rstam'}

Message: CSHARP-584: final commit consisting of proof reading doc comments.
Branch: x2.0
https://github.com/mongodb/mongo-csharp-driver/commit/3ee1be36057bfc5e5c798f5c3b516a6f22610cd4

Generated at Wed Feb 07 21:37:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.