Hi, I'm in the process of upgrading from V7 to V8 and I'm stuck on how to inject UmbracoHelper as service for global use.
My C# skills/ knowledge are/is a work in progress so if there's my use of 'inject' is incorrect, please don't kill me :) . I hope I'm able to learn something from the answer to this post.
In our current installation we very effectively utilize
private static UmbracoHelper Helper
{
get
{
return new UmbracoHelper(UmbracoContext.Current);
}
}
As you know, this 'setup' is not available in V8.
However, within each method that I call this helper I can add a 'local' instance of
Injecting/using the UmbracoHelper outside of a web request is not recommended. If you need to access things like content etc on things like background threads, you are better off injecting IUmbracoContextFactory, and the other interfaces that the UmbracoHelper wraps up.
If you find you start getting things not working as expected, or odd errors occurring this could be the reason, just so you are aware.
Umbraco 8 Inject UmbracoHelper for global use
Hi, I'm in the process of upgrading from V7 to V8 and I'm stuck on how to inject UmbracoHelper as service for global use.
My C# skills/ knowledge are/is a work in progress so if there's my use of 'inject' is incorrect, please don't kill me :) . I hope I'm able to learn something from the answer to this post.
In our current installation we very effectively utilize
As you know, this 'setup' is not available in V8.
However, within each method that I call this helper I can add a 'local' instance of
and it will work. But this doesn't feel like a good solution!
is there a way of achieving the same as we did in V7 and exposing 'helper' globally - or at least within the controller?
Thanks!
EDIT: So I found my own answer!
This:
can be replaced with:
Hi Elliot,
Injecting/using the UmbracoHelper outside of a web request is not recommended. If you need to access things like content etc on things like background threads, you are better off injecting IUmbracoContextFactory, and the other interfaces that the UmbracoHelper wraps up.
If you find you start getting things not working as expected, or odd errors occurring this could be the reason, just so you are aware.
Thanks
Nik
is working on a reply...