You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge branch 'maintenance/mapping-exceptions' into develop
Introduced the more specific `InvalidTypeException` and `MappingModelValidationException`, both of which derive from the existing `TopicMappingException`, in order to provide (even more specific) exceptions for predictable errors with the various topic mapping services.
Currently, the `InvalidTypeException` occurs when the target topic view model determined by the `Topic.ContentType` cannot be retrieved from the `ITypeLookupService`, while the `MappingModelValidationException` occurs when the `ReverseTopicMappingService` discovers a disconnect between the source model and the target `Topic` which might result in an unexpected data integrity or data loss issue when that `Topic` is `Save()`d to the persistence layer.
The [`TopicMappingService`](TopicMappingService.cs) provides a concrete implementation that is expected to satisfy the requirements of most consumers. This supports the following conventions.
@@ -186,4 +187,9 @@ While the `CachedTopicMappingService` can be useful for particular scenarios, it
186
187
187
188
1. It may take up considerable memory, depending on how many permutations of mapped objects the application has. This is especially true since it caches each unique object graph; no effort is made to centralize object instances referenced by e.g. relationships in multiple graphs.
188
189
2. It makes no effort to validate or evict cache entries. Topics whose values change during the lifetime of the `CachedTopicMappingService` will not be reflected in the mapped responses.
189
-
3. If a graph is manually constructed (by e.g. programmatically mapping `Children`) then each instance will be separated cached, thus potentially allowing an instance to be shared between multiple graphs. This can introduce concerns if edge maintenance is important.
190
+
3. If a graph is manually constructed (by e.g. programmatically mapping `Children`) then each instance will be separated cached, thus potentially allowing an instance to be shared between multiple graphs. This can introduce concerns if edge maintenance is important.
191
+
192
+
## Exceptions
193
+
The topic mapping services will throw a [`TopicMappingException`](TopicMappingException.cs) if a foreseeable exception occurs. Specifically, the exceptions expected will be:
194
+
-**[`InvalidTypeException`](InvalidTypeException.cs):** The [`TopicMappingService`](TopicMappingService.cs) throws this exception if the source `Topic`'s `ContentType` maps to a `TopicViewModel` which cannot be located in the supplied `ITypeLookupService`.
195
+
-**[`MappingModelValidationException`](MappingModelValidationException.cs):** The [`ReverseTopicMappingService`](Reverse/ReverseTopicMappingService.cs) throws this exception if the source model has any discrepancies with the target `Topic` which may introduce unexpected data integrity or data loss once that `Topic` is saved.
Copy file name to clipboardExpand all lines: OnTopic/Mapping/Reverse/README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ The [`IReverseTopicMappingService`](IReverseTopicMappingService.cs) and its conc
11
11
Unlike the `TopicMappingService`, the `ReverseTopicMappingService` will not map any plain-old C# object (POCO); binding models must implement the `ITopicBindingModel` interface, which requires a `Key` and `ContentType` property; without these, it can't create a new `Topic` instance. For relationships, it expects implementation of the `IReverseTopicMappingService`, which has a single `UniqueKey` property.
12
12
13
13
## Model Validation
14
-
The `ReverseTopicMappingService` is deliberately more conservative than the `TopicMappingService` since assumptions in mapping won't just impact a view, but will be committed to the database. As a result, all properties are validated against the corresponding `ContentTypeDescriptor`'s `AttributeDescriptors` collection. If a property cannot be mapped back to an attribute, an `InvalidOperationException` is thrown.
14
+
The `ReverseTopicMappingService` is deliberately more conservative than the `TopicMappingService` since assumptions in mapping won't just impact a view, but will be committed to the database. As a result, all properties are validated against the corresponding `ContentTypeDescriptor`'s `AttributeDescriptors` collection. If a property cannot be mapped back to an attribute, a `MappingModelValidationException` is thrown.
15
15
16
16
> _Important:_ If a binding model contains properties that are not intended to be mapped, they must explicitly be excluded from mapping using the `[DisableMapping]` attribute.
0 commit comments