Am i still able to do this in Umbraco 9+ i cant seem to find anything in the Docs everything pushes you towards using dependancy injection which i cant in the Static Umbraco Helper.
I assume the alternative is to make it a service instead and inject that in to the view but im porting a large site from Umbraco 8 to 11, keeping it as UmbracoHelper function would reduce code changes
I understand that a migration to a new version is a lot of work and it makes sense to not touch every bit of code and rewrite everything. But at least place it on a backlog to rewrite the helper into a service instead of a static class.
Although the service locator should work, it's not the prefered approach.
Getting An Umbraco service in a UmbracoHelper Extension
Before in Umbraco 8 i was able to get a service inside a static function for example a UmbracoHelper Extension like so
Am i still able to do this in Umbraco 9+ i cant seem to find anything in the Docs everything pushes you towards using dependancy injection which i cant in the Static Umbraco Helper.
I assume the alternative is to make it a service instead and inject that in to the view but im porting a large site from Umbraco 8 to 11, keeping it as UmbracoHelper function would reduce code changes
Hi Perry
You probably shouldn't do it, but there is a static service provider you can use. It's described here: https://www.andybutland.dev/2022/03/service-location-in-umbraco-9.html
I understand that a migration to a new version is a lot of work and it makes sense to not touch every bit of code and rewrite everything. But at least place it on a backlog to rewrite the helper into a service instead of a static class.
Although the service locator should work, it's not the prefered approach.
is working on a reply...