Copied to clipboard

Flag this post as spam?

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


  • Steven Lemmens 30 posts 71 karma points
    Jul 07, 2013 @ 16:20
    Steven Lemmens
    0

    How to use the ContentService from MacroPartial?

    I'm wondering how to use the ContentService from a MacroPartial (MVC)? 

    I can't use Services.ContentService - or at least, that throws an error that 'Services' doesn't exist in the current context. How should I go about this? 

    I'm running 6.1.2, MVC version. Tried searching the documentation for this piece of information, but no luck.

     

    Anyone can help me out?

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Jul 07, 2013 @ 17:33
    Morten Christensen
    0

    You have to have using Umbraco.Core; and the you should be able to get the service from ApplicationContext.Current.Services.ContentService.

    Alternatively you can get the ApplicationContext through the UmbracoContext.

     

    PS: remember to use the ContentService with care when accessed from the frontend of a website, as it will usually mean database is hit (there is some caching depending which actions you use).

     

    - Morten

  • Steven Lemmens 30 posts 71 karma points
    Jul 07, 2013 @ 18:02
    Steven Lemmens
    0

    Morten, thanks for the help.

    If I just get a Node (with its children) through the Content Service, will that mean that the databse is hit, or that the cache is hit?

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Jul 07, 2013 @ 18:12
    Morten Christensen
    0

    Its will be cached on first hit, but only stay cached for 5min as far as I remember.

    If there is not a specific reason to get Content/IContent objects then we always recommend using IPublishedContent. Think its documented under Querying.

    If you need to create or publish content or otherwise manipulate it, then the ContentService is the right thing to use. Almost everything else would use Published/Cached content (what we call IPublishedContent, which is retrieved from the XML cache).

     

    - Morten

Please Sign in or register to post replies

Write your reply to:

Draft