Access IPublishedContent outside of a request

I need to get some content when not operating within the context of a request. IUmbracoHelperAccessor.TryGetUmbracoHelper(...) is also not usable as the underlying HttpContext is null.

How is this possible?

A context is the context base on a request (based on the http request). If there is no request, there is no context. However, you can create an Umbraco context. From memory, you need to do this (or close to it)

public class Foo (IUmbracoContextFactory umbracoContextFactory)
{
  public void Bar() 
  {
    using var context =  umbracoContextFactory.EnsureUmbracoContext();

    //access content, example
    var rootItems =   context .Content.GetAtRoot();
  }
}

Thanks for this. This put me down a path of looking at the new methods of getting content within Umbraco and we’ve come across IPublishedContentQuery which is accessible outside of the request scope.