Copied to clipboard

Flag this post as spam?

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


  • Ulf Möllerström 70 posts 247 karma points
    Jun 04, 2021 @ 11:35
    Ulf Möllerström
    0

    DI without DI...

    Hi folks! I have a CRUD service that is accessed in an api controller, and this is wired up by Umbraco by DI (I found an example here).

    enter image description here enter image description here

    But now I need to use the CRUD service outside of this context, but I am fairly lost how to inject the IScopeProvider "manually" or in some kind of composer.

    Any help/hints appreciated! (Before I revert to ol' PetaPoco in a separate project...)

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Jun 06, 2021 @ 10:06
    Huw Reddick
    100

    you should be able to use the scope without DI like below

    using (var scope = Current.ScopeProvider.CreateScope(autoComplete: true))
    {
        var database = scope.Database;
    
        var result = database.Query<ConfigData>("SELECT * FROM VantageConfig WHERE C_NAME=@0", fieldname).FirstOrDefault();
    
        return result != null;
    }
    
  • john blair 48 posts 219 karma points
    Jul 26, 2023 @ 16:35
    john blair
    0

    Hi, Current is not available in Umbraco 11. How would I access it there?

  • Ulf Möllerström 70 posts 247 karma points
    Jun 06, 2021 @ 18:33
    Ulf Möllerström
    0

    Ahh... It sits on "Currnet" - great!

  • Johannes Lantz 156 posts 839 karma points c-trib
    Jun 06, 2021 @ 19:28
    Johannes Lantz
    0

    Välkommen till Umbraco 8 Ulf! ;) <3

  • Ulf Möllerström 70 posts 247 karma points
    Jun 07, 2021 @ 09:11
    Ulf Möllerström
    0

    * L O L *

Please Sign in or register to post replies

Write your reply to:

Draft