This project is read-only.

Error on programmatically getting elements of custom content part

Topics: Writing modules
Apr 6, 2014 at 10:17 AM
I'm creating module for Orchard CMS - viewer widget for elements of custom ContentType.

So, I have interface for service:
public interface IReviewGrabber : IDependency 
    IEnumerable<ReviewPart> Reviews { get; }
And it's implementation:
public class ReviewGrabber : IReviewGrabber
    readonly IOrchardServices _orchardServices;
    readonly IEnumerable<ReviewPart> _reviews;

    public ReviewGrabber(IOrchardServices orchardServices)
        _orchardServices = orchardServices;
        var temp = _orchardServices.ContentManager.Query<ReviewPart, ReviewRecord>();
        _reviews = temp.List();

public IEnumerable<ReviewPart> Reviews
        get { return _reviews; }
And handler for ContentType:
public class ReviewHandler : ContentHandler
    public ReviewHandler(IRepository<ReviewRecord> repository)
Debugging this, I've added element of type Review manually, and it works. In ReviewGrabber class variable temp fills correctly, but calling method List() for it fires error:

ValueFactory tries to access the Value property of this instance.

_handlers.Value '_handlers.Value' threw an exception of type 'System.InvalidOperationException' System.Collections.Generic.IEnumerable {System.InvalidOperationException}

on row
public IEnumerable<IContentHandler> Handlers {
     get { return _handlers.Value; }
in DefaultContentManager.cs

What's wrong? Thank you!
Apr 6, 2014 at 3:50 PM
Can you try this: Change Reviews property to a method, say GetReviews(), and call the query in it, something like that:

public IEnumerable<ReviewPart> GetReviews() {
return _orchardServices.ContentManager.Query<ReviewPart, ReviewRecord>().List();

and remove the query from the constructor, as it's supposed to initialize the dependencies only.