ASP.NET mvc controller disposed while processing ASP.NET identity Usermanager.CreateAsync method





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















The asp.net mvc controller is disposed by Windsor Castle container while calling asp.net identity usermanager.CreateAsync method



UserManager.CreateAsync method is calling FindByNameAsync first which returns null and the expected CreateAsync in UserStore is not called as the mvc controller is disposed by Windsor DI container.
Any Help would be appreciated.



Code:



// custom implementation of UserStore
public class UserStore : IUserStore<ApplicationUser,int>
{
#region IUserStore

// create a new user
public Task CreateAsync(ApplicationUser user)
{
if (user != null)
{
return Task.Factory.StartNew(() =>
{
// UserSerivce.NewUser(user); // TODO
});

}
throw new ArgumentNullException("user");
}
}

// controller method
[HttpPost]
public async Task<ActionResult> Register(RegisterModel model)
{
if (ModelState.IsValid)
{
//model.Password need to be hashed
var user = new ApplicationUser { UserName = model.Email, Email = model.Email, PasswordHash = model.Password}; // populate other data
var result = await UserManager.CreateAsync(user);// calls FindByNameAsync first and then not calling CreateAsync as Controller instance is disposed.

if (result.Succeeded)
{
}
}
}


public class UserStore : IUserStore<ApplicationUser,int>
{
#region IUserStore

// does not get called as controller disposed before calling this.
// create a new user
public Task CreateAsync(ApplicationUser user)
{
if (user != null)
{
return Task.Factory.StartNew(() =>
{
// use User Service in services folder.
// UserController.NewUser(user); // TODO
});

}
throw new ArgumentNullException("user");
}

// gets called ok.
public Task<ApplicationUser> FindByNameAsync(string userName)
{
if (!string.IsNullOrEmpty(userName))
{
// check with db
return null; // for testing
}
throw new ArgumentNullException("userName");
}

}


// windsor DI container
public class MvcControllersInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Classes.FromThisAssembly()
.BasedOn<IController>()
.LifestylePerWebRequest());
}
}









share|improve this question































    0















    The asp.net mvc controller is disposed by Windsor Castle container while calling asp.net identity usermanager.CreateAsync method



    UserManager.CreateAsync method is calling FindByNameAsync first which returns null and the expected CreateAsync in UserStore is not called as the mvc controller is disposed by Windsor DI container.
    Any Help would be appreciated.



    Code:



    // custom implementation of UserStore
    public class UserStore : IUserStore<ApplicationUser,int>
    {
    #region IUserStore

    // create a new user
    public Task CreateAsync(ApplicationUser user)
    {
    if (user != null)
    {
    return Task.Factory.StartNew(() =>
    {
    // UserSerivce.NewUser(user); // TODO
    });

    }
    throw new ArgumentNullException("user");
    }
    }

    // controller method
    [HttpPost]
    public async Task<ActionResult> Register(RegisterModel model)
    {
    if (ModelState.IsValid)
    {
    //model.Password need to be hashed
    var user = new ApplicationUser { UserName = model.Email, Email = model.Email, PasswordHash = model.Password}; // populate other data
    var result = await UserManager.CreateAsync(user);// calls FindByNameAsync first and then not calling CreateAsync as Controller instance is disposed.

    if (result.Succeeded)
    {
    }
    }
    }


    public class UserStore : IUserStore<ApplicationUser,int>
    {
    #region IUserStore

    // does not get called as controller disposed before calling this.
    // create a new user
    public Task CreateAsync(ApplicationUser user)
    {
    if (user != null)
    {
    return Task.Factory.StartNew(() =>
    {
    // use User Service in services folder.
    // UserController.NewUser(user); // TODO
    });

    }
    throw new ArgumentNullException("user");
    }

    // gets called ok.
    public Task<ApplicationUser> FindByNameAsync(string userName)
    {
    if (!string.IsNullOrEmpty(userName))
    {
    // check with db
    return null; // for testing
    }
    throw new ArgumentNullException("userName");
    }

    }


    // windsor DI container
    public class MvcControllersInstaller : IWindsorInstaller
    {
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
    container.Register(Classes.FromThisAssembly()
    .BasedOn<IController>()
    .LifestylePerWebRequest());
    }
    }









    share|improve this question



























      0












      0








      0








      The asp.net mvc controller is disposed by Windsor Castle container while calling asp.net identity usermanager.CreateAsync method



      UserManager.CreateAsync method is calling FindByNameAsync first which returns null and the expected CreateAsync in UserStore is not called as the mvc controller is disposed by Windsor DI container.
      Any Help would be appreciated.



      Code:



      // custom implementation of UserStore
      public class UserStore : IUserStore<ApplicationUser,int>
      {
      #region IUserStore

      // create a new user
      public Task CreateAsync(ApplicationUser user)
      {
      if (user != null)
      {
      return Task.Factory.StartNew(() =>
      {
      // UserSerivce.NewUser(user); // TODO
      });

      }
      throw new ArgumentNullException("user");
      }
      }

      // controller method
      [HttpPost]
      public async Task<ActionResult> Register(RegisterModel model)
      {
      if (ModelState.IsValid)
      {
      //model.Password need to be hashed
      var user = new ApplicationUser { UserName = model.Email, Email = model.Email, PasswordHash = model.Password}; // populate other data
      var result = await UserManager.CreateAsync(user);// calls FindByNameAsync first and then not calling CreateAsync as Controller instance is disposed.

      if (result.Succeeded)
      {
      }
      }
      }


      public class UserStore : IUserStore<ApplicationUser,int>
      {
      #region IUserStore

      // does not get called as controller disposed before calling this.
      // create a new user
      public Task CreateAsync(ApplicationUser user)
      {
      if (user != null)
      {
      return Task.Factory.StartNew(() =>
      {
      // use User Service in services folder.
      // UserController.NewUser(user); // TODO
      });

      }
      throw new ArgumentNullException("user");
      }

      // gets called ok.
      public Task<ApplicationUser> FindByNameAsync(string userName)
      {
      if (!string.IsNullOrEmpty(userName))
      {
      // check with db
      return null; // for testing
      }
      throw new ArgumentNullException("userName");
      }

      }


      // windsor DI container
      public class MvcControllersInstaller : IWindsorInstaller
      {
      public void Install(IWindsorContainer container, IConfigurationStore store)
      {
      container.Register(Classes.FromThisAssembly()
      .BasedOn<IController>()
      .LifestylePerWebRequest());
      }
      }









      share|improve this question
















      The asp.net mvc controller is disposed by Windsor Castle container while calling asp.net identity usermanager.CreateAsync method



      UserManager.CreateAsync method is calling FindByNameAsync first which returns null and the expected CreateAsync in UserStore is not called as the mvc controller is disposed by Windsor DI container.
      Any Help would be appreciated.



      Code:



      // custom implementation of UserStore
      public class UserStore : IUserStore<ApplicationUser,int>
      {
      #region IUserStore

      // create a new user
      public Task CreateAsync(ApplicationUser user)
      {
      if (user != null)
      {
      return Task.Factory.StartNew(() =>
      {
      // UserSerivce.NewUser(user); // TODO
      });

      }
      throw new ArgumentNullException("user");
      }
      }

      // controller method
      [HttpPost]
      public async Task<ActionResult> Register(RegisterModel model)
      {
      if (ModelState.IsValid)
      {
      //model.Password need to be hashed
      var user = new ApplicationUser { UserName = model.Email, Email = model.Email, PasswordHash = model.Password}; // populate other data
      var result = await UserManager.CreateAsync(user);// calls FindByNameAsync first and then not calling CreateAsync as Controller instance is disposed.

      if (result.Succeeded)
      {
      }
      }
      }


      public class UserStore : IUserStore<ApplicationUser,int>
      {
      #region IUserStore

      // does not get called as controller disposed before calling this.
      // create a new user
      public Task CreateAsync(ApplicationUser user)
      {
      if (user != null)
      {
      return Task.Factory.StartNew(() =>
      {
      // use User Service in services folder.
      // UserController.NewUser(user); // TODO
      });

      }
      throw new ArgumentNullException("user");
      }

      // gets called ok.
      public Task<ApplicationUser> FindByNameAsync(string userName)
      {
      if (!string.IsNullOrEmpty(userName))
      {
      // check with db
      return null; // for testing
      }
      throw new ArgumentNullException("userName");
      }

      }


      // windsor DI container
      public class MvcControllersInstaller : IWindsorInstaller
      {
      public void Install(IWindsorContainer container, IConfigurationStore store)
      {
      container.Register(Classes.FromThisAssembly()
      .BasedOn<IController>()
      .LifestylePerWebRequest());
      }
      }






      asp.net-mvc asp.net-identity






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 13:31









      tereško

      52.7k2178136




      52.7k2178136










      asked Nov 16 '18 at 11:09









      user6340505user6340505

      13




      13
























          0






          active

          oldest

          votes












          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%2f53336679%2fasp-net-mvc-controller-disposed-while-processing-asp-net-identity-usermanager-cr%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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%2f53336679%2fasp-net-mvc-controller-disposed-while-processing-asp-net-identity-usermanager-cr%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

          Florida Star v. B. J. F.

          Error while running script in elastic search , gateway timeout

          Adding quotations to stringified JSON object values