mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 17:08:47 +08:00
Lazy field loading using content item ContentManager instead of the injected one. (#8725)
* Lazy field loading using content item ContentManager instead of the injected one. * Removed unused _contentManager variable
This commit is contained in:
parent
a4be7c68cb
commit
03884cbd64
@ -6,14 +6,11 @@ using Orchard.ContentPicker.Fields;
|
||||
|
||||
namespace Orchard.ContentPicker.Handlers {
|
||||
public class ContentPickerFieldHandler : ContentHandler {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||
|
||||
public ContentPickerFieldHandler(
|
||||
IContentManager contentManager,
|
||||
IContentDefinitionManager contentDefinitionManager) {
|
||||
|
||||
_contentManager = contentManager;
|
||||
_contentDefinitionManager = contentDefinitionManager;
|
||||
}
|
||||
|
||||
@ -30,7 +27,8 @@ namespace Orchard.ContentPicker.Handlers {
|
||||
|
||||
foreach (var field in fields) {
|
||||
var localField = field;
|
||||
field._contentItems.Loader(() => _contentManager.GetMany<ContentItem>(localField.Ids, VersionOptions.Published, QueryHints.Empty));
|
||||
// Using context content item's ContentManager instead of injected one to avoid lifetime scope exceptions in case of LazyFields.
|
||||
field._contentItems.Loader(() => context.ContentItem.ContentManager.GetMany<ContentItem>(localField.Ids, VersionOptions.Published, QueryHints.Empty));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,16 +9,12 @@ using Orchard.MediaLibrary.Models;
|
||||
|
||||
namespace Orchard.MediaLibrary.Handlers {
|
||||
public class MediaLibraryPickerFieldHandler : ContentHandler {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||
|
||||
public MediaLibraryPickerFieldHandler(
|
||||
IContentManager contentManager,
|
||||
IContentDefinitionManager contentDefinitionManager) {
|
||||
|
||||
_contentManager = contentManager;
|
||||
_contentDefinitionManager = contentDefinitionManager;
|
||||
|
||||
}
|
||||
|
||||
protected override void Loaded(LoadContentContext context) {
|
||||
@ -37,7 +33,8 @@ namespace Orchard.MediaLibrary.Handlers {
|
||||
|
||||
foreach (var field in fields) {
|
||||
var localField = field;
|
||||
localField._contentItems = new Lazy<IEnumerable<MediaPart>>(() => _contentManager.GetMany<MediaPart>(localField.Ids, VersionOptions.Published, QueryHints.Empty).ToList());
|
||||
// Using context content item's ContentManager instead of injected one to avoid lifetime scope exceptions in case of LazyFields.
|
||||
localField._contentItems = new Lazy<IEnumerable<MediaPart>>(() => contentItem.ContentManager.GetMany<MediaPart>(localField.Ids, VersionOptions.Published, QueryHints.Empty).ToList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user