Skip to content

Commit f1ade10

Browse files
committed
Introduced new SetContentTypeDescriptors() method
Previously, the `GetContentTypeDescriptors(ContentTypeDescriptor)` method provided a way of retrieving the content type descriptor cache, but also a way of updating it. In practice, in most of the places it was used, it was semantically being used purely to update the cache, either because a content type was missing, or because the metadata was being modified. Given that, it makes more sense to rename it to `SetContentTypeDescriptors()`. Because `GetContentTypeDescriptors()` was already published as part of the public interface, however, it's being marked as deprecated via `[Obsolete()]`, and will be removed in the next major version of the library (5.0.0).
1 parent afbfa47 commit f1ade10

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

OnTopic/Repositories/TopicRepositoryBase.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,32 @@ public virtual ContentTypeDescriptorCollection GetContentTypeDescriptors() {
105105
/// also any descendents.
106106
/// </param>
107107
/// <returns></returns>
108-
protected virtual ContentTypeDescriptorCollection GetContentTypeDescriptors(ContentTypeDescriptor? contentTypeDescriptors) {
108+
[Obsolete("Deprecated. Instead, use the new SetContentTypeDescriptors() method, which provides the same function.", false)]
109+
protected virtual ContentTypeDescriptorCollection GetContentTypeDescriptors(ContentTypeDescriptor? contentTypeDescriptors)
110+
=> SetContentTypeDescriptors(contentTypeDescriptors);
109111

112+
/*==========================================================================================================================
113+
| SET CONTENT TYPE DESCRIPTORS
114+
\-------------------------------------------------------------------------------------------------------------------------*/
115+
/// <summary>
116+
/// Allows for the content type descriptor cache to be (re)initialized based on an in-memory topic graph, starting with
117+
/// the root <see cref="ContentTypeDescriptor"/>.
118+
/// </summary>
119+
/// <remarks>
120+
/// By default, the <see cref="SetContentTypeDescriptors(ContentTypeDescriptor?)"/> method will load data from the
121+
/// concrete implementation of the <see cref="ITopicRepository"/>'s data store. There are cases, however, where it may be
122+
/// preferrable to instead load these topics from a local, in-memory source. Namely, when first instantiating a new
123+
/// OnTopic database, and when saving modifications to existing content types. As such, the <c>protected</c> <see cref=
124+
/// "SetContentTypeDescriptors(ContentTypeDescriptor?)"/> method is useful to call from <see cref="ITopicRepository.Save(
125+
/// Topic, Boolean, Boolean)"/> when the topic graph being saved includes any new <see cref="ContentTypeDescriptor"/>s.
126+
/// </remarks>
127+
/// <param name="rootContentType">
128+
/// The root of a <see cref="ContentTypeDescriptor"/> topic graph to merge into the collection for <see
129+
/// cref="SetContentTypeDescriptors(ContentTypeDescriptor?)"/>. The code will process not only the root <see cref=
130+
/// "ContentTypeDescriptor"/>, but also any descendents.
131+
/// </param>
132+
/// <returns></returns>
133+
protected virtual ContentTypeDescriptorCollection SetContentTypeDescriptors(ContentTypeDescriptor? rootContentType) {
110134

111135
/*------------------------------------------------------------------------------------------------------------------------
112136
| Establish cache
@@ -116,7 +140,7 @@ protected virtual ContentTypeDescriptorCollection GetContentTypeDescriptors(Cont
116140
| mixing objects from different topic graphs. Instead, we always assume that the source collection is the most accurate
117141
| and relevant.
118142
\-----------------------------------------------------------------------------------------------------------------------*/
119-
_contentTypeDescriptors.Refresh(contentTypeDescriptors);
143+
_contentTypeDescriptors.Refresh(rootContentType);
120144

121145
/*------------------------------------------------------------------------------------------------------------------------
122146
| Validate cache

0 commit comments

Comments
 (0)