@@ -57,53 +57,44 @@ internal static bool RegisterOutboxClassMappings()
5757 // If any of the class maps are already registered, then we assume that the user has provided their own custom class maps
5858 // and treat the entire tree as custom.
5959 var usesDefaultClassMap = true ;
60- if ( ! BsonClassMap . IsClassMapRegistered ( typeof ( OutboxRecordId ) ) )
61- {
62- BsonClassMap . RegisterClassMap < OutboxRecordId > ( cm =>
63- {
64- cm . AutoMap ( ) ;
65- cm . MapMember ( x => x . PartitionKey ) . SetElementName ( "pk" ) ;
66- cm . MapMember ( x => x . MessageId ) . SetElementName ( "mid" ) ;
67- } ) ;
68- }
69- else
60+
61+ if ( ! TryRegisterOutboxRecordId ( ) )
7062 {
7163 usesDefaultClassMap = false ;
7264 }
7365
74- if ( ! BsonClassMap . IsClassMapRegistered ( typeof ( OutboxRecord ) ) )
75- {
76- BsonClassMap . RegisterClassMap < OutboxRecord > ( cm =>
77- {
78- cm . AutoMap ( ) ;
79- cm . MapIdMember ( x => x . Id ) . SetSerializer ( new OutboxRecordIdSerializer ( ) ) ;
80- } ) ;
81- }
82- else
66+ if ( ! TryRegisterOutboxRecord ( ) )
8367 {
8468 usesDefaultClassMap = false ;
8569 }
8670
87- if ( ! BsonClassMap . IsClassMapRegistered ( typeof ( StorageTransportOperation ) ) )
88- {
89- BsonClassMap . RegisterClassMap < StorageTransportOperation > ( cm =>
90- {
91- cm . AutoMap ( ) ;
92- cm . MapMember ( c => c . Headers )
93- . SetSerializer (
94- new DictionaryInterfaceImplementerSerializer < Dictionary < string , string > > (
95- DictionaryRepresentation . ArrayOfDocuments ) ) ;
96- cm . MapMember ( c => c . Options )
97- . SetSerializer (
98- new DictionaryInterfaceImplementerSerializer < Dictionary < string , string > > (
99- DictionaryRepresentation . ArrayOfDocuments ) ) ;
100- } ) ;
101- }
102- else
71+ if ( ! TryRegisterStorageTransportOperation ( ) )
10372 {
10473 usesDefaultClassMap = false ;
10574 }
10675
10776 return usesDefaultClassMap ;
10877 }
78+
79+ static bool TryRegisterOutboxRecordId ( ) => BsonClassMap . TryRegisterClassMap < OutboxRecordId > ( cm =>
80+ {
81+ cm . AutoMap ( ) ;
82+ cm . MapMember ( x => x . PartitionKey ) . SetElementName ( "pk" ) ;
83+ cm . MapMember ( x => x . MessageId ) . SetElementName ( "mid" ) ;
84+ } ) ;
85+
86+ static bool TryRegisterOutboxRecord ( ) => BsonClassMap . TryRegisterClassMap < OutboxRecord > ( cm =>
87+ {
88+ cm . AutoMap ( ) ;
89+ cm . MapIdMember ( x => x . Id ) . SetSerializer ( new OutboxRecordIdSerializer ( ) ) ;
90+ } ) ;
91+
92+ static bool TryRegisterStorageTransportOperation ( ) => BsonClassMap . TryRegisterClassMap < StorageTransportOperation > ( cm =>
93+ {
94+ cm . AutoMap ( ) ;
95+ cm . MapMember ( c => c . Headers )
96+ . SetSerializer ( new DictionaryInterfaceImplementerSerializer < Dictionary < string , string > > ( DictionaryRepresentation . ArrayOfDocuments ) ) ;
97+ cm . MapMember ( c => c . Options )
98+ . SetSerializer ( new DictionaryInterfaceImplementerSerializer < Dictionary < string , string > > ( DictionaryRepresentation . ArrayOfDocuments ) ) ;
99+ } ) ;
109100}
0 commit comments