TigerMan
06/19/2024, 11:58 AMD_Inventor
06/19/2024, 12:01 PMStaticServiceProvider
class and I would highly recommend against using it.
The UmbracoHelper
can only be fetched in a thread that is handling a request for an Umbraco content page. Outside that, you don't have the umbraco helper available.
Read more about dependency injection here:
https://docs.umbraco.com/umbraco-cms/v/13.latest-lts/reference/using-ioc
Read more about umbraco helper here:
https://docs.umbraco.com/umbraco-cms/v/13.latest-lts/reference/querying/umbracohelperTigerMan
06/19/2024, 12:21 PMD_Inventor
06/19/2024, 12:23 PMD_Inventor
06/19/2024, 12:23 PMTigerMan
06/19/2024, 12:27 PMD_Inventor
06/19/2024, 12:29 PMStaticServiceProvider
in your class? If so, you should instead add IUmbracoHelperAccessor
in the constructor of your class and rely on that instead.D_Inventor
06/19/2024, 12:31 PMc#
public class MyCustomClass
{
private readonly IUmbracoHelperAccessor _umbracoHelperAccessor;
public MyCustomClass(IUmbracoHelperAccessor umbracoHelperAccessor)
{
_umbracoHelperAccessor = umbracoHelperAccessor;
}
public void MyCustomMethod()
{
var umbracoHelper = _umbracoHelperAccessor.GetRequiredUmbracoHelper();
// ... use the umbraco helper
}
}
TigerMan
06/19/2024, 12:42 PM