The short answer is: You shouldn't really be doing that.
You should be injecting dependencies you need. You can usually do this in the constructor of the class you want to "depend" on your instance, but you can also do it in Views too. See https://our.umbraco.com/documentation/reference/using-ioc/
Getting Current.Factory.GetInstance in v9?
Hi all, hope someone can help me with this.
I have the following code which does not work any more in umbraco v.9:
How can I use Current.Factory.GetInstance in Umbraco v.9 ?
The short answer is: You shouldn't really be doing that.
You should be injecting dependencies you need. You can usually do this in the constructor of the class you want to "depend" on your instance, but you can also do it in Views too. See https://our.umbraco.com/documentation/reference/using-ioc/
To inject a dependency in a view you can do:
@inject IFooBar fooBar
See https://docs.microsoft.com/en-us/aspnet/core/mvc/views/dependency-injection?view=aspnetcore-6.0
You can also inject dependencies in View Components, which can replace traditional partials - see https://our.umbraco.com/Documentation/Reference/Templating/Mvc/ViewComponents
Hi @Fa
As Dan says you should be injecting all the things...
... but ... if you really really really couldn't inject your dependency in a particular scenario, then there is an equivalent in V9
Umbraco.Cms.Web.Common.DependencyInjection.StaticServiceProvider
which allows you to locate services registered in the Dependency Injection container, that you just can't access in your context via actual injection.
eg
but don't tell anyone I told you :-P
regards
Marc
Thanks Marc Goodson and Dan Diplo. I did go with injecting all the things and it is working fine. :)
is working on a reply...