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 118 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 1929 posts 6697 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);
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft