Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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
You can also inject dependencies in View Components, which can replace traditional partials - see https://our.umbraco.com/Documentation/Reference/Templating/Mvc/ViewComponents
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
which allows you to locate services registered in the Dependency Injection container, that you just can't access in your context via actual injection.
but don't tell anyone I told you :-P
Thanks Marc Goodson and Dan Diplo. I did go with injecting all the things and it is working fine. :)
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted