Copied to clipboard

Flag this post as spam?

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


  • Joseph 59 posts 140 karma points
    Jun 25, 2015 @ 20:49
    Joseph
    0

    How do I query for IPublishedContent without UmbracoContext?

    I've been working through introducing some parallelism to (custom-built) long running tasks (mainly in the backoffice - these are mainly tools that I've built to automate adding content to the system, etc); I've been simply using Task.Run( () => { ... } );

    I know that I can get access to the services via ApplicationContext.Current.Services; however I've not figured out how to query for IPublishedContent - which as far as I am aware is done via the UmbracoHelper which needs an UmbracoContext. I could probably do what I need using the ContentService but that feels a little wrong as what I'm really wanting to be doing is to query for information in a read-only manner.

    Is there currently a way to do this via the available APIs?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 25, 2015 @ 21:53
    Alex Skrypnyk
    100

    Hi Joseph,

    Why you don't want to use Services? Services are for backend, IPublishedContent for front-end, but I agree with you that it makes sense to use IPublishedContent for read-only data.

    You can create context object and use it:

    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    
    var frontPage = umbracoHelper.TypedContent(id);
    

    Thanks, Alex

Please Sign in or register to post replies

Write your reply to:

Draft