Using content item's ContentManager for lazy field loading instead of the injected one (#8761)

This commit is contained in:
Andrea Piovanelli 2024-02-29 19:37:54 +01:00 committed by GitHub
parent 44bfa390bc
commit 90dc993e83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<TermPart>(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<TermPart>(fieldTermRecordIds, VersionOptions.Published, queryHint);
return terms.ToList();
});
}
@ -73,7 +74,8 @@ namespace Orchard.Taxonomies.Handlers {
part._termParts = new LazyField<IEnumerable<TermContentItemPart>>();
part._termParts.Loader(() => {
var ids = part.Terms.Select(t => t.TermRecord.Id).Distinct();
var terms = _contentManager.GetMany<TermPart>(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<TermPart>(ids, VersionOptions.Published, queryHint)
.ToDictionary(t => t.Id, t => t);
return
part.Terms.Select(