Copied to clipboard

Flag this post as spam?

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


  • Nagarjun 39 posts 71 karma points
    Dec 14, 2020 @ 08:23
    Nagarjun
    0

    Accessing Umbraco services in startup class.

    Hi,

    Can anyone let me know on how to access Umbraco services like logger service , member service, user service in start up class file. I want to assign a different role based on the claims I receive from external identity like Azure active directory.

    public partial class Startup
    {
    public void ConfigureAuth(IAppBuilder app)
    {
    adOptions.SetExternalSignInAutoLinkOptions(
                new ExternalSignInAutoLinkOptions(autoLinkExternalAccount: true, defaultUserGroups: null, defaultCulture: null)
                {
                    OnAutoLinking = (user, externalLogin) => {
    
    
                    }
    
                    ,OnExternalLogin = (user, externalLogin) => {
                        return true;
                    }
    
                });
    
    }
    }
    
  • Dhanesh Kumar MJ 165 posts 521 karma points MVP c-trib
    Dec 14, 2020 @ 14:20
    Dhanesh Kumar MJ
    0

    Hi Nagarjuna,

    You can consume services like this

    Example Userservice

    var userService = Umbraco.Core.Composing.Current.Services.UserService;
    

    Regards Dhanesh :)

  • Evan Moore 4 posts 75 karma points c-trib
    Jul 19, 2021 @ 18:54
    Evan Moore
    0

    I have the same question. How do we access services in Umbraco 9 during ConfigureServices? Specifically, when the OnExternalLogin action is run, I would like to be able to modify a user by accessing the IBackOfficeUserManager.

    I've tried getting the service using an IServiceProvider like so

        var provider = services.BuildServiceProvider();
        _userManager = provider.GetService<IBackOfficeUserManager>();
    

    But I seem to get errors that

    Register called when MainDom has not been acquired
    

    Umbraco.Core.Composing doesn't exist in Umbraco 9, and doesn't seem like a very .Net 5 way of doing things anyway.

    Any ideas?

Please Sign in or register to post replies

Write your reply to:

Draft