Extending UserManager results in ObjectDisposedException












0















If I extend the generated aspnetboilerplate UserManager class (from the startup template), any time I use the RoleManager I receive a ObjectDisposedException exception. I assume this is related to dependency injection. Is there something obvious I am doing wrong (or should not be doing)?



Here is the UserManager class definition (with the method I added at the bottom)



namespace MyProject.Authorization.Users
{
public class UserManager : AbpUserManager<Role, User>
{
public UserManager(
RoleManager roleManager,
UserStore store,
IOptions<IdentityOptions> optionsAccessor,
IPasswordHasher<User> passwordHasher,
IEnumerable<IUserValidator<User>> userValidators,
IEnumerable<IPasswordValidator<User>> passwordValidators,
ILookupNormalizer keyNormalizer,
IdentityErrorDescriber errors,
IServiceProvider services,
ILogger<UserManager<User>> logger,
IPermissionManager permissionManager,
IUnitOfWorkManager unitOfWorkManager,
ICacheManager cacheManager,
IRepository<OrganizationUnit, long> organizationUnitRepository,
IRepository<UserOrganizationUnit, long> userOrganizationUnitRepository,
IOrganizationUnitSettings organizationUnitSettings,
ISettingManager settingManager)
: base(
roleManager,
store,
optionsAccessor,
passwordHasher,
userValidators,
passwordValidators,
keyNormalizer,
errors,
services,
logger,
permissionManager,
unitOfWorkManager,
cacheManager,
organizationUnitRepository,
userOrganizationUnitRepository,
organizationUnitSettings,
settingManager)
{
}

public void GoBoom()
{
var role = RoleManager.Roles.FirstOrDefault();
}
}
}


Usage (here, directly injected and used on a razor view)



@inject MyProject.Authorization.Users.UserManager _userManager
@{
_userManager.GoBoom();
}









share|improve this question



























    0















    If I extend the generated aspnetboilerplate UserManager class (from the startup template), any time I use the RoleManager I receive a ObjectDisposedException exception. I assume this is related to dependency injection. Is there something obvious I am doing wrong (or should not be doing)?



    Here is the UserManager class definition (with the method I added at the bottom)



    namespace MyProject.Authorization.Users
    {
    public class UserManager : AbpUserManager<Role, User>
    {
    public UserManager(
    RoleManager roleManager,
    UserStore store,
    IOptions<IdentityOptions> optionsAccessor,
    IPasswordHasher<User> passwordHasher,
    IEnumerable<IUserValidator<User>> userValidators,
    IEnumerable<IPasswordValidator<User>> passwordValidators,
    ILookupNormalizer keyNormalizer,
    IdentityErrorDescriber errors,
    IServiceProvider services,
    ILogger<UserManager<User>> logger,
    IPermissionManager permissionManager,
    IUnitOfWorkManager unitOfWorkManager,
    ICacheManager cacheManager,
    IRepository<OrganizationUnit, long> organizationUnitRepository,
    IRepository<UserOrganizationUnit, long> userOrganizationUnitRepository,
    IOrganizationUnitSettings organizationUnitSettings,
    ISettingManager settingManager)
    : base(
    roleManager,
    store,
    optionsAccessor,
    passwordHasher,
    userValidators,
    passwordValidators,
    keyNormalizer,
    errors,
    services,
    logger,
    permissionManager,
    unitOfWorkManager,
    cacheManager,
    organizationUnitRepository,
    userOrganizationUnitRepository,
    organizationUnitSettings,
    settingManager)
    {
    }

    public void GoBoom()
    {
    var role = RoleManager.Roles.FirstOrDefault();
    }
    }
    }


    Usage (here, directly injected and used on a razor view)



    @inject MyProject.Authorization.Users.UserManager _userManager
    @{
    _userManager.GoBoom();
    }









    share|improve this question

























      0












      0








      0








      If I extend the generated aspnetboilerplate UserManager class (from the startup template), any time I use the RoleManager I receive a ObjectDisposedException exception. I assume this is related to dependency injection. Is there something obvious I am doing wrong (or should not be doing)?



      Here is the UserManager class definition (with the method I added at the bottom)



      namespace MyProject.Authorization.Users
      {
      public class UserManager : AbpUserManager<Role, User>
      {
      public UserManager(
      RoleManager roleManager,
      UserStore store,
      IOptions<IdentityOptions> optionsAccessor,
      IPasswordHasher<User> passwordHasher,
      IEnumerable<IUserValidator<User>> userValidators,
      IEnumerable<IPasswordValidator<User>> passwordValidators,
      ILookupNormalizer keyNormalizer,
      IdentityErrorDescriber errors,
      IServiceProvider services,
      ILogger<UserManager<User>> logger,
      IPermissionManager permissionManager,
      IUnitOfWorkManager unitOfWorkManager,
      ICacheManager cacheManager,
      IRepository<OrganizationUnit, long> organizationUnitRepository,
      IRepository<UserOrganizationUnit, long> userOrganizationUnitRepository,
      IOrganizationUnitSettings organizationUnitSettings,
      ISettingManager settingManager)
      : base(
      roleManager,
      store,
      optionsAccessor,
      passwordHasher,
      userValidators,
      passwordValidators,
      keyNormalizer,
      errors,
      services,
      logger,
      permissionManager,
      unitOfWorkManager,
      cacheManager,
      organizationUnitRepository,
      userOrganizationUnitRepository,
      organizationUnitSettings,
      settingManager)
      {
      }

      public void GoBoom()
      {
      var role = RoleManager.Roles.FirstOrDefault();
      }
      }
      }


      Usage (here, directly injected and used on a razor view)



      @inject MyProject.Authorization.Users.UserManager _userManager
      @{
      _userManager.GoBoom();
      }









      share|improve this question














      If I extend the generated aspnetboilerplate UserManager class (from the startup template), any time I use the RoleManager I receive a ObjectDisposedException exception. I assume this is related to dependency injection. Is there something obvious I am doing wrong (or should not be doing)?



      Here is the UserManager class definition (with the method I added at the bottom)



      namespace MyProject.Authorization.Users
      {
      public class UserManager : AbpUserManager<Role, User>
      {
      public UserManager(
      RoleManager roleManager,
      UserStore store,
      IOptions<IdentityOptions> optionsAccessor,
      IPasswordHasher<User> passwordHasher,
      IEnumerable<IUserValidator<User>> userValidators,
      IEnumerable<IPasswordValidator<User>> passwordValidators,
      ILookupNormalizer keyNormalizer,
      IdentityErrorDescriber errors,
      IServiceProvider services,
      ILogger<UserManager<User>> logger,
      IPermissionManager permissionManager,
      IUnitOfWorkManager unitOfWorkManager,
      ICacheManager cacheManager,
      IRepository<OrganizationUnit, long> organizationUnitRepository,
      IRepository<UserOrganizationUnit, long> userOrganizationUnitRepository,
      IOrganizationUnitSettings organizationUnitSettings,
      ISettingManager settingManager)
      : base(
      roleManager,
      store,
      optionsAccessor,
      passwordHasher,
      userValidators,
      passwordValidators,
      keyNormalizer,
      errors,
      services,
      logger,
      permissionManager,
      unitOfWorkManager,
      cacheManager,
      organizationUnitRepository,
      userOrganizationUnitRepository,
      organizationUnitSettings,
      settingManager)
      {
      }

      public void GoBoom()
      {
      var role = RoleManager.Roles.FirstOrDefault();
      }
      }
      }


      Usage (here, directly injected and used on a razor view)



      @inject MyProject.Authorization.Users.UserManager _userManager
      @{
      _userManager.GoBoom();
      }






      aspnetboilerplate






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 18:14









      MakoMako

      584




      584
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Add [UnitOfWork] attribute and make it a virtual method:



          [UnitOfWork]
          public virtual void GoBoom()
          {
          ...
          }


          See: UnitOfWork Attribute Restrictions




          You can use UnitOfWork attribute for:




          • All public or public virtual methods for classes that are used over an interface (Like an application service used over a service interface).

          • All public virtual methods for self-injected classes (Like MVC Controllers and Web API Controllers).

          • All protected virtual methods.







          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287191%2fextending-usermanager-results-in-objectdisposedexception%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Add [UnitOfWork] attribute and make it a virtual method:



            [UnitOfWork]
            public virtual void GoBoom()
            {
            ...
            }


            See: UnitOfWork Attribute Restrictions




            You can use UnitOfWork attribute for:




            • All public or public virtual methods for classes that are used over an interface (Like an application service used over a service interface).

            • All public virtual methods for self-injected classes (Like MVC Controllers and Web API Controllers).

            • All protected virtual methods.







            share|improve this answer




























              1














              Add [UnitOfWork] attribute and make it a virtual method:



              [UnitOfWork]
              public virtual void GoBoom()
              {
              ...
              }


              See: UnitOfWork Attribute Restrictions




              You can use UnitOfWork attribute for:




              • All public or public virtual methods for classes that are used over an interface (Like an application service used over a service interface).

              • All public virtual methods for self-injected classes (Like MVC Controllers and Web API Controllers).

              • All protected virtual methods.







              share|improve this answer


























                1












                1








                1







                Add [UnitOfWork] attribute and make it a virtual method:



                [UnitOfWork]
                public virtual void GoBoom()
                {
                ...
                }


                See: UnitOfWork Attribute Restrictions




                You can use UnitOfWork attribute for:




                • All public or public virtual methods for classes that are used over an interface (Like an application service used over a service interface).

                • All public virtual methods for self-injected classes (Like MVC Controllers and Web API Controllers).

                • All protected virtual methods.







                share|improve this answer













                Add [UnitOfWork] attribute and make it a virtual method:



                [UnitOfWork]
                public virtual void GoBoom()
                {
                ...
                }


                See: UnitOfWork Attribute Restrictions




                You can use UnitOfWork attribute for:




                • All public or public virtual methods for classes that are used over an interface (Like an application service used over a service interface).

                • All public virtual methods for self-injected classes (Like MVC Controllers and Web API Controllers).

                • All protected virtual methods.








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 '18 at 22:32









                aaronaaron

                8,64131131




                8,64131131






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287191%2fextending-usermanager-results-in-objectdisposedexception%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    List item for chat from Array inside array React Native

                    Thiostrepton

                    Caerphilly