Copied to clipboard

Flag this post as spam?

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


  • Jimmy 19 posts 119 karma points
    Jun 11, 2024 @ 10:28
    Jimmy
    0

    How to use UmbracoHelper in an Interface?

    Hi guys

    I'm using Umbraco 13 and created my own Interface.

    Part of the derived class is injecting UmbracoHelper into the constructor.

    When I try and use it across my application, I received the error

    'cannot consume scoped service Umbraco. CMS.web.common.umbracohelper'

    How could I use it inject Umbraco Helper into my classes/interfaces and register them properly?

  • Huw Reddick 1932 posts 6722 karma points MVP 2x c-trib
    Jun 12, 2024 @ 06:39
    Huw Reddick
    100

    you could maybe try instantiating it rather than using DI

        var accessor = StaticServiceProvider.Instance.GetRequiredService<IUmbracoHelperAccessor>();
    
        if (accessor.TryGetUmbracoHelper(out var umbracoHelper))
        {
            return umbracoHelper.Content(id);
        }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies