Essentially the 'Umbraco' in Umbraco.Content and Umbraco.Media is an instance of the UmbracoHelper class provided for convenience in Views, Controllers etc - but no so in a Component, where it cannot be guaranteed that an UmbracoContext will exist, the UmbracoHelper relies on their being an UmbracoContext.
In the example above you can see the use of the UmbracoContextFactory to ensure the context exists, to get a reference to the UmbracoContext to allow you to query the content or media caches.
How to use umbraco.contnet() in Icomponent ?
Hi
i am going to write a method that implement on save and publish so i write a class that inherit from I Component
public class MyComponent : IComponent
and start to write my method
but i cant using umbraco.content() neither umbraco.media() in this class
how can i solve this problem ?
Hi Mus'ab
Have a look at this example in the documentation.
https://our.umbraco.com/Documentation/Implementation/Services/#accessing-published-content-outside-of-a-http-request
Essentially the 'Umbraco' in Umbraco.Content and Umbraco.Media is an instance of the UmbracoHelper class provided for convenience in Views, Controllers etc - but no so in a Component, where it cannot be guaranteed that an UmbracoContext will exist, the UmbracoHelper relies on their being an UmbracoContext.
In the example above you can see the use of the UmbracoContextFactory to ensure the context exists, to get a reference to the UmbracoContext to allow you to query the content or media caches.
if that helps?
regards
Marc
is working on a reply...