Copied to clipboard

Flag this post as spam?

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


  • Johan Dahlström 33 posts 146 karma points
    Jul 06, 2020 @ 12:29
    Johan Dahlström
    0

    Get IPublishedContent by id from class library

    I have a class library referencing Umbraco.Core (8.6.3). How can I access IPublishedContent by id from that project?

    Both IUmbracoContextFactory and UmbracoContext.Content are a part of Umbraco.Web. I would like to avoid adding a reference to that package in my class library, since it's not web-related.

    What I'm after is to access content with or without the preview flag, like UmbracoContext.Content.GetById(preview, id)

  • Jason Elkin 38 posts 351 karma points MVP 2x c-trib
    Jul 06, 2020 @ 15:08
    Jason Elkin
    100

    You'll need to reference Umbraco.Web

    The IPublishedContent you're after will come from the cache/context of a running Umbraco web-site. Whether or not what you're doing is "web related", you want to work with part of Umbraco that is.

    In the case of Umbraco ".Web" isn't an allusion to the UI/Presentation Layer.

  • Johan Dahlström 33 posts 146 karma points
    Jul 06, 2020 @ 17:32
    Johan Dahlström
    0

    Yeah, I thought I had to pull the "UmbracoCms" package to access .Web, but was happy to see that "UmbracoCms.Web" was a separate package. Didn't want to bloat the class lib with views and files from the UmbracoCms package.

Please Sign in or register to post replies

Write your reply to:

Draft