locked
Initializing & Using Custom User Store in asp.net Identity RRS feed

  • Question

  • User1856468055 posted

    Hi I am creating custom user store as:

    public class UserStore<TKey> : IUserStore<User<TKey>>
    {
      private DbConnection _connection;
      /// <summary>
      ///     Database connection for User 
      /// </summary>
      /// <value>The connection.</value>
      public DbConnection Connection {
    	get { return _connection; }
    	set {
    		if ( value == null )
    			throw new ArgumentNullException( _emsg_ConnectioIsRequired );
    			_connection = value;
    	}
    	}  		
      public UserStore( DbConnection connection ) {
    			Connection = connection;
    		}
    
      #region IUserStore implementation
        //Implementation goes here
      #end region
    }

    Then in my account controller I need to instantiate this user store to which I am having problems. 

    I have something like this:

    namespace Web.Controllers  
    {
        public class AccountController : Controller
        {
            public AccountController()
                : this(new UserManager<User<string>>(new UserStore<User<string>>())) 
            // above this throws error as user store does not contain a constructor that takes 0 arguments
            {
            }
    
            public AccountController(UserManager<User<string>> userManager)
            {
                UserManager = userManager;
            }
    
            public UserManager<User<string>> UserManager { get; private set; }
    
    }

    Could you please help me in.

    Thanks

    Wednesday, September 24, 2014 10:04 AM

Answers

  • User-734925760 posted

    Hi,

    According to your code and the error message, it want to tell us that we need to create a constructor.

    I have created a MVC project and pasted your code to my project, then created a constructor without arguments, it error will disappear。

    So I suggest you trying to create a constructor without arguments as below code in UserStore class:

     public UserStore() { }

    Hope it's useful for you.

    Best Regards,

    Michelle Ge

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 25, 2014 4:40 AM