Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Khupi 7 posts 117 karma points
    Apr 20, 2022 @ 09:48
    Khupi
    0

    IPublishedContentQuery Composer dependency injection error

    public class WebPComponent: IComponent { private readonly IMediaService _mediaService; private readonly IPublishedContentQuery _publishedContentQuery; //private readonly IMediaTypeService _mediaTypeService;

        public WebPComponent(IMediaService mediaService, IPublishedContentQuery publishedContentQuer) 
        {
            _mediaService = mediaService;
            _publishedContentQuery = publishedContentQuer;
        }
    

    When i exclude the IPublisherQuery from the constructor, including only the IMediaService it run without issues? Wht might be the issue with injecting IPublisherQuery service on the composer and what is the solution?

    this is a summary of the error im getting when starting umbraco

  • Marc Goodson 2157 posts 14411 karma points MVP 9x c-trib
    Apr 21, 2022 @ 21:43
    Marc Goodson
    100

    Hi Khupi

    The short of it is IPublished ContentQuery relies on there being an Umbraco Context on the thread and 'inside a component' you are not guaranteed that there will be one...

    There is a bit of documentation here that explains it:

    https://our.umbraco.com/Documentation/Implementation/Services/index-v8#accessing-core-services-and-helpers-when-there-is-no-umbracocontext-eg-in-a-component-or-c-class

    And shows you how you can query the umbraco cache in this scenario

    Regards

    Marc

  • Khupi 7 posts 117 karma points
    Apr 22, 2022 @ 08:11
    Khupi
    0

    Thanks Marc. Ill check it out

Please Sign in or register to post replies

Write your reply to:

Draft