V8 ContentService.Published event how to access the url of the published node
I subscribe to the ContentService.Published event in umbraco 8. The PublishedEntities is a collection of IContent which has no Url property. How do I get the Url?
Note: You would think that as this is the Published event - not the Publishing one...that you would be given the IPublishedContent which has a url property - but unfortunately not!
Also how do you get an UmbracoHelper in the ContentService.Published event ... I'm thinking I could use that to access Content(id) method to get a IPublishedContent but again it seems Umbraco make it difficult to access this.
var helper = Umbraco.Web.Composing.Current.UmbracoHelper;
var publishedContent = helper.Content(content.Id);
var url = publishedContent.Url(mode: UrlMode.Absolute)
V8 ContentService.Published event how to access the url of the published node
I subscribe to the ContentService.Published event in umbraco 8. The PublishedEntities is a collection of IContent which has no Url property. How do I get the Url?
Note: You would think that as this is the Published event - not the Publishing one...that you would be given the IPublishedContent which has a url property - but unfortunately not!
Also how do you get an UmbracoHelper in the ContentService.Published event ... I'm thinking I could use that to access Content(id) method to get a IPublishedContent but again it seems Umbraco make it difficult to access this.
Thanks for any help.
Seems a bit of a hack but I'm using :
You can inject
IUmbracoContextFactory
in your component which allows you to retrieve published entities.Thanks a lot...that worked a treat.
Per your suggestion it is better to inject what you need than just pull in a global UmbracoHelper.
Now that I'm injecting what I need - I needed a logger in my component so injected that too to help with debugging.
The server side is becoming more like the angularjs client side where you just inject the services you need.
Would be nice if there was a list of available "injectable" services somewhere.
is working on a reply...