Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Fa 2 posts 72 karma points
    Jul 04, 2022 @ 08:54

    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:

     return Current.Factory.TryGetInstance<T>();

    How can I use Current.Factory.GetInstance in Umbraco v.9 ?

  • Dan Diplo 1553 posts 6170 karma points MVP 4x c-trib
    Jul 04, 2022 @ 09:29
    Dan Diplo

    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

    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

  • Marc Goodson 1717 posts 11410 karma points MVP 7x c-trib
    Jul 04, 2022 @ 11:27
    Marc Goodson

    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


    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



  • Fa 2 posts 72 karma points
    25 days ago

    Thanks Marc Goodson and Dan Diplo. I did go with injecting all the things and it is working fine. :)

Please Sign in or register to post replies

Write your reply to: