I have a controller that calls out to a class that is injected using AutoFac, This class needs to make use of the Umbraco APIs specifically TypedContentAtRoot()
Within My class I have carried out the following
UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var MyRootItem = umbracoHelper.TypedContentAtRoot();
My question is should I be creating the UmbracoHelper in this way as based on the Common Pitfalls document it states don't use UmbracoContext.Current
Am I missing something How should I create the UmbracoHelper if I shouldn't use UmbracoContext.Current .
I have looked around the web and there are a number discussions but I'm still not clear so any information would be really useful.
Advice on Common Pitfalls
I have been reading through the Anti-Patterns document found at https://our.umbraco.org/documentation/Reference/Common-Pitfalls/ and I am a little confused with first item "Usage of Singletons and Statics".
I have a controller that calls out to a class that is injected using AutoFac, This class needs to make use of the Umbraco APIs specifically TypedContentAtRoot()
Within My class I have carried out the following
My question is should I be creating the UmbracoHelper in this way as based on the Common Pitfalls document it states don't use UmbracoContext.Current
Am I missing something How should I create the UmbracoHelper if I shouldn't use UmbracoContext.Current .
I have looked around the web and there are a number discussions but I'm still not clear so any information would be really useful.
Paul,
In the past we have also injected umbracohelper in using IOC in this instance it was ninject so:
then
The IUmbracoService is our own wrapper that makes use of umbraco helper to get nodes in same way you are eg TypeContentAtRoot()
Regards
Ismail
Hello,
I was going to start a new thread but this one is what I need. I've been reading the Anti patterns and pitfalls, too. I came across this line:
In one of the websites I developed I have this:
If I understand correctly, this is fine as long as it's not static?
is working on a reply...