Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6066053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:27:34+00:00 2026-05-23T09:27:34+00:00

How do I communicate with the UserService through an overidden MembershipProvider class? I have

  • 0

How do I communicate with the UserService through an overidden MembershipProvider class? I have no idea how to pass the connection string to the user repository inside the service.

This is how my app is structured:

Repository (constructor in the implementation takes a connection string)

public interface IUserRepository
{
    IQueryable<User> GetUsers();
    IQueryable<UserRole> GetUserRoles();
    void InsertUser(User user);
}

Service (Constructor takes a user repository)

public interface IUserService
{
    User GetUser(int userId);
    User GetUser(string email);
}

UserController (An example of my controller)

public class UsersController : Controller
{
    private IUserService userService;
    public UsersController(IUserService userServ)
    {
        userService = userServ;
    }
}

NinjectConfigurationModule

public class NinjectConfigurationModule : NinjectModule
{

    public override void Load()
    {
        Bind<IUserService>().To<UserService>();
        Bind<IUserRepository>().To<UserRepository>()
            .WithConstructorArgument("connectionString", ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString
            );
    }
}

NinjectControllerFactory

public class NinjectControllerFactory : DefaultControllerFactory
{
    private IKernel kernel = new StandardKernel(new NinjectConfigurationModule());

    protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
    {
        // We don't want to pass null to ninject as we'll get a strange error.
        return controllerType == null ? null
                                      : (IController)kernel.Get(controllerType);
    }
}

MembershipProvider (This is where my problem is)

public class SimpleMembershipProvider : MembershipProvider
{
     //How do I set up User Service here so that ninject can put my connection string here.
     public override bool ValidateUser(string username, string password)
     {
           //Code to use user service.
     }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:27:34+00:00Added an answer on May 23, 2026 at 9:27 am

    Already answered question, but I think the better answer is to make the repository a property on your MembershipProvider and inject into it at Application_Start. e.g.

    public class AccountMembershipProvider : MembershipProvider
    {
        [Inject]
        public IAccountRepository AccountRepository { get; set; }
        ...
    }
    

    and the injection:

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
    
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
    
            // Inject account repository into our custom membership & role providers.
            _kernel.Inject(Membership.Provider);
    
            // Register the Object Id binder.
            ModelBinders.Binders.Add(typeof(ObjectId), new ObjectIdModelBinder()); 
        }
    

    I’ve written up a more in depth explanation here:

    http://www.danharman.net/2011/06/23/asp-net-mvc-3-custom-membership-provider-with-repository-injection/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To communicate with a certain service, I have to override the WindProc . and
I'm trying to communicate with Flash Media Server through the Responder class because I
I'm trying to communicate with a bluetooth device. The information I have on the
I should communicate with an online service that sends me the following data urlencoded:
So I want to communicate with an OracleDB through my Android app. Allowing users
My client will communicate with clients using a struct/class called annoucement. I suppose I
I'm trying to communicate to a device using RS-485 through the serial port. Everything
I am trying to communicate with Excel from a Java/SWT application. I have been
Can AJAX communicate with MySQL directly? For example, I just have a simple text
Our application needs to communicate with another program through a COM interface. The interface

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.