From 90dc993e83ff6ba33e309c31f77c5cdaf119278f Mon Sep 17 00:00:00 2001 From: Andrea Piovanelli <83577153+AndreaPiovanelli@users.noreply.github.com> Date: Thu, 29 Feb 2024 19:37:54 +0100 Subject: [PATCH] Using content item's ContentManager for lazy field loading instead of the injected one (#8761) --- .../Modules/Orchard.Taxonomies/Handlers/TermsPartHandler.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Taxonomies/Handlers/TermsPartHandler.cs b/src/Orchard.Web/Modules/Orchard.Taxonomies/Handlers/TermsPartHandler.cs index 2abf96d34..1a73399d0 100644 --- a/src/Orchard.Web/Modules/Orchard.Taxonomies/Handlers/TermsPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/Handlers/TermsPartHandler.cs @@ -65,7 +65,8 @@ namespace Orchard.Taxonomies.Handlers { var tempField = field.Name; field.TermsField.Loader(() => { var fieldTermRecordIds = part.Record.Terms.Where(t => t.Field == tempField).Select(tci => tci.TermRecord.Id); - var terms = _contentManager.GetMany(fieldTermRecordIds, VersionOptions.Published, queryHint); + // Using context content item's ContentManager instead of injected one to avoid lifetime scope exceptions in case of LazyFields. + var terms = part.ContentItem.ContentManager.GetMany(fieldTermRecordIds, VersionOptions.Published, queryHint); return terms.ToList(); }); } @@ -73,7 +74,8 @@ namespace Orchard.Taxonomies.Handlers { part._termParts = new LazyField>(); part._termParts.Loader(() => { var ids = part.Terms.Select(t => t.TermRecord.Id).Distinct(); - var terms = _contentManager.GetMany(ids, VersionOptions.Published, queryHint) + // Using context content item's ContentManager instead of injected one to avoid lifetime scope exceptions in case of LazyFields. + var terms = part.ContentItem.ContentManager.GetMany(ids, VersionOptions.Published, queryHint) .ToDictionary(t => t.Id, t => t); return part.Terms.Select(