Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ private void InitializerTermsLoader(TermsPart part) {
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();
});
}

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(
Expand Down