Unless something new was added in 7.1 that I'm not aware of, then yes, that is the way to get IPublishedContent.
I'm not entirely sure how much overhead there is in creating an UmbracoHelper, but I tend to at least make sure I only create one once per request when needed.
Best practice to get ipublished in class
Hello,
I have the following in a config service class:
Is this the best way to get IPublishedContent in a class? I am doing this way so then i can make use of propertyconvertors dll by Jeavon http://our.umbraco.org/projects/developer-tools/umbraco-core-property-editor-converters
Regards
Ismail
This is the way I have been doing it when I am outside of the context of a controller or usercontrol. I dont think there is a better way.
Unless something new was added in 7.1 that I'm not aware of, then yes, that is the way to get IPublishedContent.
I'm not entirely sure how much overhead there is in creating an UmbracoHelper, but I tend to at least make sure I only create one once per request when needed.
Cheers
Mads
Mads and Pete,
Awesome many thanks. With regards to performance its a singleton so will only be fired up once.
Regards
Ismail
This topic has some more info about it: http://our.umbraco.org/forum/developers/api-questions/37894-new-Dynamic
This is my solution which I prefer over the Umbraco helper: http://our.umbraco.org/forum/developers/api-questions/37894-new-Dynamic?p=5#comment152555
Jeroen
Jeroen,
Does not work unless i am missing some references or something?
Yes, when UmbracoHelper was born, Shannon sent me a sample which was like this:
I have been using it ever since
Jeavon
@Ismail that example should work if you have the UmbracoHelper available.
So this could also work:
But why not use the other example?
That will always return the current page and you don't need to create your own helper first.
I always use it like this:
Jeroen
Some more info. I copied that from how the RenderMvcController also returns the current page: https://github.com/umbraco/Umbraco-CMS/blob/7.1.1/src/Umbraco.Web/Mvc/RenderMvcController.cs#LC45
Jeroen
is working on a reply...