Skip to content

Commit 946ddb9

Browse files
committed
Migrated GetContentTypes() to new Refresh() method
Migrated the `TopicRepositoryBase.GetContentTypes()` method to utilize the newly introduced `ContentTypeDescriptorCollection.Refresh()` method (3e3930f). This prevents it from needing to rely on the `GetContentTypes(ContentTypeDescriptor)` overload for centralizing functionality—which, in turn, depended on an unintuitive state tracking via the `_contentTypeDescriptors` field initialization to avoid a circular loop (since each function calls into the other). As part of this, I was also able to make the `_contentTypeDescriptors` field readonly, thus helping avoid a confusing scenario where updating the cache would change which `ContentTypeDescriptorCollection` the field referenced, thus orphaning any preexisting references. Finally, I renamed `allowedContentTypes` to `contentTypes` to avoid confusion. (`AllowsContentTypes` is a property/attribute used to track what content types can be created under an instead of a particular content type. That concept doesn't apply here, thus the name is misleading.)
1 parent 6c081d8 commit 946ddb9

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

OnTopic/Repositories/TopicRepositoryBase.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public abstract class TopicRepositoryBase : ITopicRepository {
3131
/*==========================================================================================================================
3232
| PRIVATE VARIABLES
3333
\-------------------------------------------------------------------------------------------------------------------------*/
34-
private ContentTypeDescriptorCollection? _contentTypeDescriptors = null;
34+
private readonly ContentTypeDescriptorCollection _contentTypeDescriptors = new ContentTypeDescriptorCollection();
3535

3636
/*==========================================================================================================================
3737
| EVENT HANDLERS
@@ -57,20 +57,15 @@ public virtual ContentTypeDescriptorCollection GetContentTypeDescriptors() {
5757
/*------------------------------------------------------------------------------------------------------------------------
5858
| Initialize content types
5959
\-----------------------------------------------------------------------------------------------------------------------*/
60-
if (_contentTypeDescriptors == null) {
61-
62-
/*----------------------------------------------------------------------------------------------------------------------
63-
| Initialize cache
64-
\---------------------------------------------------------------------------------------------------------------------*/
65-
_contentTypeDescriptors = new ContentTypeDescriptorCollection();
60+
if (_contentTypeDescriptors.Count == 0) {
6661

6762
/*----------------------------------------------------------------------------------------------------------------------
6863
| Load configuration data
6964
\---------------------------------------------------------------------------------------------------------------------*/
7065
var configuration = (Topic?)null;
7166

7267
try {
73-
configuration = Load("Configuration");
68+
configuration = Load("Configuration");
7469
}
7570
catch (TopicNotFoundException) {
7671
//Swallow missing configuration, as this is an expected condition when working with a new database
@@ -79,12 +74,12 @@ public virtual ContentTypeDescriptorCollection GetContentTypeDescriptors() {
7974
/*----------------------------------------------------------------------------------------------------------------------
8075
| Load root content type
8176
\---------------------------------------------------------------------------------------------------------------------*/
82-
var allowedContentTypes = configuration?.Children.GetTopic("ContentTypes") as ContentTypeDescriptor;
77+
var contentTypes = configuration?.Children.GetTopic("ContentTypes") as ContentTypeDescriptor;
8378

8479
/*----------------------------------------------------------------------------------------------------------------------
8580
| Add available Content Types to the collection
8681
\---------------------------------------------------------------------------------------------------------------------*/
87-
_contentTypeDescriptors = GetContentTypeDescriptors(allowedContentTypes);
82+
_contentTypeDescriptors.Refresh(contentTypes);
8883

8984
}
9085

0 commit comments

Comments
 (0)