Copied to clipboard

Flag this post as spam?

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


  • Devin Bost 37 posts 78 karma points c-trib
    Oct 29, 2014 @ 01:40
    Devin Bost
    0

    How do I get the IPublishedContent instead of IContent? From ApplicationContext?

    Hi,

    I am trying to avoid being late on a deadline. To get the IContent objects by ID from my web api method, I would use code like this:

    IContent foundUmbracoContent = ApplicationContext.Current.Services.ContentService.GetById(nodeId);
    

    However, I have been informed that this value is not cached and thus has slower performance than working with IPublishedContent objects. Unfortunately, it appears that IPublishedContent objects are not provided by any method of ApplicationContext.Current.Services.ContentService. There is a ApplicationContext.Current.Services.ContentService.GetPublishedVersion(nodeId) that I could use, but that still returns an IContent object, so I have no way to determine if it will return the cached version of the object (and I have no time for performance testing this object).

    How do I obtain the IPublishedContent or equivalently cached version of the object from my Web API (GET) method?

    Thanks in advance.

  • Jamie Howarth 306 posts 773 karma points c-trib
    Oct 29, 2014 @ 02:07
    Jamie Howarth
    1

    You need to use UmbracoContext.Current.ContentCache instead of ApplicationContext.

    ContentCache returns IPublishedContent instead of the ContentService in ApplicationContext.Current.Services.

    HTH

    Benjamin

  • bhavana 1 post 71 karma points
    Apr 01, 2016 @ 15:39
    bhavana
    0

    Hi Benjamin,

    How can i get the ContentCache object using DI ?

    Thanks, Vivek

  • Dan Lister 416 posts 1974 karma points c-trib
    Oct 29, 2014 @ 09:28
    Dan Lister
    2

    Hi Devin,

    You can create an instance of the UmbracoHelper class using the current Umbraco Context. For example:

    var helper = new UmbracoHelper(UmbracoContext.Current);
    IPublishedContent publishedContent = helper.TypedContent(1234);
    

    Thanks, Dan.

Please Sign in or register to post replies

Write your reply to:

Draft