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

  • SEARCH
  • Home
  • 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 7037463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:32:54+00:00 2026-05-28T01:32:54+00:00

This is similar to Dependency Injection with Custom Membership Provider , but the responses

  • 0

This is similar to Dependency Injection with Custom Membership Provider, but the responses there don’t solve the issue for me.

I have a custom membership provider which has a dependency to a repository class. ASP.NET will always instantiate this using the parameter-less constructor, so to resolve the dependency to the repository I have a kind of service locator method … my ctor looks like this:

public CustomMembershipProvider()
{
    _userRepository = AppStart_NinjectMVC3.Resolve<IUserRepository>();
}

And that Resolve method looks like this..

public static T Resolve<T>() where T : class
{
    return _kernel.Get<T>();
}

This works fine when I run the web app, because _kernel is correctly setup. However, I need to test the methods on my membership provider.. So when my test code tries to invoke the methods on membership provider it will instantiate a new membership provider class with the paramter-less ctor, which errors because _kernel is not setup.

What I want to do is somehow inject my FakeUserRepository class instead, but how can I achieve that?

  • 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-28T01:32:54+00:00Added an answer on May 28, 2026 at 1:32 am

    I think I have a work round for this…

    I’ve added a ctor to the membership provider which accepts a repository instance, and then I’ve manually instantiated my membership provider in my test class like this:

    var prov = new CableSenseMembershipProvider(new FakeUserRepository());
            var config = new NameValueCollection();
            config.Add("applicationName", "ddd");
            config.Add("name", "CustomMembershipProvider");
            config.Add("requiresQuestionAndAnswer", "false");
            config.Add("requiresUniqueEmail", "false");
            prov.Initialize(config["name"], config);
    

    Once I’ve dont this I can then invoke that instance and not worry about the parameter-less ctor being called.

    As an aside, you still need to add the membership section to your test project app.config or it wont work – which is somewhat confusing!

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

Sidebar

Related Questions

I have checked this similar question, but the suggestions did not solve my problem:
(this is similar to GNU make: Execute target but take dependency from file but
I have a multimodule web project with a dependency graph similar to this WAR-project
In an ASP.NET MVC application when using a custom Dependency Injection container (in this
I found this similar question here , but this is really old. Was it
This is similar to this question, which is about a bash file . We've
This is similar to an earlier problem I was having which you guys solved
This is similar to (but different from) this question . Here is some simple
Does anyone know how to have dependency injection work with linq2sql. Heres my situation..
I have built a javascript/css dependency manager similar to http://code.google.com/p/jingo/ . It allows me

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.