Copied to clipboard

Flag this post as spam?

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


  • Dev 8 posts 79 karma points
    Sep 30, 2022 @ 08:13
    Dev
    0

    Please suggest which is the best approach for Fetching the Umbraco content in UmbracoAPIController

    Hi @all,

    I gone through the documentation of Umbraco services & helpers, and now iam little bit confused :(

    I am creating an API controller (UmbracoAPI) for fetching the Umbraco content, so I need to find, what are the services available in Umbraco and what I understand is below are those services..

        private readonly IPublishedContentQuery _publishedContentQuery;
        private readonly IUmbracoContextFactory _umbracoContextFactory;
        private readonly IUmbracoHelperAccessor _umbracoHelper;
    

    But which one I need to use and which is the best approach. In the documentation itself ,while using IUmbracoContextFactory there might be a chance for occurring circular dependency(and they suggested to use Lazy to resolve those issue) ,but again why there is three different services for the same functionality ,I'm confused :(

    Can anyone please suggest me the best approach.

    Regards Dev

  • Huw Reddick 832 posts 2820 karma points
    Sep 30, 2022 @ 15:22
    Huw Reddick
    0

    I usually use the IContentService, but it depends what you want to do with the content.

  • Dev 8 posts 79 karma points
    Oct 03, 2022 @ 07:28
    Dev
    0

    Hi Huw Reddick,

    Thanks for the reply.

    But ContentService is good to used for the create/modify/delete operations right?, because it will hit in the DB right?

    In my case, I just want to FETCH the Content using UmbracoAPIController.

    Regards

  • Huw Reddick 832 posts 2820 karma points
    Oct 03, 2022 @ 07:41
    Huw Reddick
    0

    If all you want is to read the data I would use IPublishedContentQuery

  • Dev 8 posts 79 karma points
    Oct 04, 2022 @ 06:38
    Dev
    0

    Thanks.

    Do you know ,actually where we need to use these

     private readonly IUmbracoContextFactory _umbracoContextFactory;
        private readonly IUmbracoHelperAccessor _umbracoHelper;
    

    is there any benefits ?, these are also hit in cache right? same as

    IPublishedContentQuery

Please Sign in or register to post replies

Write your reply to:

Draft