Copied to clipboard

Flag this post as spam?

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

  • Jimmy 7 posts 96 karma points
    1 week ago

    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 1815 posts 6249 karma points MVP 2x c-trib
    6 days ago
    Huw Reddick

    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: