diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs index 10362b3b664..c061d7efd4c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs @@ -1,5 +1,7 @@ +using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata; @@ -23,12 +25,13 @@ public class TaxonomyIndex : MapIndex public class TaxonomyIndexProvider : IndexProvider, IScopedIndexProvider { + private readonly IServiceProvider _serviceProvider; private readonly HashSet _ignoredTypes = new HashSet(); private IContentDefinitionManager _contentDefinitionManager; - public TaxonomyIndexProvider(IContentDefinitionManager contentDefinitionManager) + public TaxonomyIndexProvider(IServiceProvider serviceProvider) { - _contentDefinitionManager = contentDefinitionManager; + _serviceProvider = serviceProvider; } public override void Describe(DescribeContext context) @@ -47,6 +50,9 @@ public override void Describe(DescribeContext context) return null; } + // Lazy initialization because of ISession cyclic dependency + _contentDefinitionManager = _contentDefinitionManager ?? _serviceProvider.GetRequiredService(); + // Search for Taxonomy fields var fieldDefinitions = _contentDefinitionManager .GetTypeDefinition(contentItem.ContentType)