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 1010727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:07:41+00:00 2026-05-16T09:07:41+00:00

I am building an asp.net MVC2 web app using StructureMap. I have created a

  • 0

I am building an asp.net MVC2 web app using StructureMap. I have created a custom MembershipProvider. I get it properly initialized at startup by calling:

x.For<MembershipProvider>().Use(Membership.Provider);
x.For<IMembershipProvider>().Use<CPOPMembershipProvider>();

In Initialize(), I am thinking of instantiating a repository to use for access to User data in the database.

So, I put in a private property in my custom MembershipProvider:

private IUserRepository userRepository;

And, inside Initialize(), I call:

IUserRepository userRepository = ObjectFactory.GetInstance<IUserRepository>();

First, is it “good practice” to instantiate a repository in my custom MembershipProvider?

Second, when I implement it, it seems like I can’t access any StructureMap configuration that was properly setup in global.asax. When I call Debug.WriteLine(ObjectFactory.WhatDoIHave()) just before the above GetInstance() line, none of the configuration data is present (which I do see from the same Debug line placed in global.asax) and I get a “No Default Instance defined for PluginFamily CPOP.Domain.Contracts.Repositories.IUserRepository” error when calling GetInstance(). Why is that? Seems like I have a whole different container inside MembershipProvider.

  • 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-16T09:07:41+00:00Added an answer on May 16, 2026 at 9:07 am

    Ended up using setter injection in StructureMap. The userRepository property in the custom MembershipProvider can be configured by calling:

    CPOPMembershipProvider member =
         (CPOPMembershipProvider) Membership.Providers["CPOPMembershipProvider"];
    ObjectFactory.Configure(x =>
    {
        ...
        x.For<MembershipProvider>().Use(Membership.Provider);
        x.For<IMembershipProvider>().TheDefault.Is.Object(member);
        ...
        x.For<IPatientRepository>().Use<PatientRepository>();
        x.For<IUserRepository>().Use<UserRepository>();
        x.SetAllProperties(y => { y.OfType<IUserRepository>(); });
        ...
    }); 
    

    And, then calling BuildUp() on a target instance. I do this in Application_Start(), after all the registries have been called and StructureMap has all the configuration data.

    ObjectFactory.BuildUp(Membership.Providers["CPOPMembershipProvider"]);
    

    Done.

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

Sidebar

Related Questions

I´m building an asp.net app, which technology I should use to get AJAX capabilities?
I'm building an ASP.NET MVC app and I'm using a repository to store and
I'm in the process of building my first web application using ASP.NET MVC 2
I'm building ASP.NET MVC2 application, and using Entity Framework as ORM. I am having
I'm building an asp.net MVC 2 app. I have a list view which lists
I am building an ASP.NET site using Visual Studio 2008 and have a page
We have a web application written in ASP.NET for .NET 3.5, using standard web
I have a custom routehandler in ASP.NET MVC2 to catch all url's at a
I'm building a project with ASP.NET MVC2 and i have a problem. According to
I am building an ASP.NET MVC web application and I'm using jQuery for some

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.