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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:04:58+00:00 2026-05-18T05:04:58+00:00

I have registered a custom MembershipProvider class in my Web.Config file. I’m using Inversion

  • 0

I have registered a custom MembershipProvider class in my Web.Config file. I’m using Inversion Of Control using Castle Windsor and I have registered my custom MembershipProvider class as transient (because it’s using a service that’s transient as well).

This means that I want the Membership provider instance recreated on every web request. Currently, it is created only once per application domain so when it tries to access the service it depends on, that service instance is reused while it is not supposed to.

Now I need to find a way of having Windsor control the lifetime of my custom MembershipProvider but I don’t know how. I expected a factory sitting around somewhere in the .NET Framework, allowing me to override the instance creation and rerouting it to Windsor but I can’t find anything alike.

By the way, I’m using .NET 4.0.

UPDATE: Here’s some of my code so you can see what I’m doing exactly:

Web.Config:

<membership defaultProvider="MyMembershipProvider" >
  <providers>
    <clear/>
    <add name="ApplicationMembershipProvider"
         type="MyNamespace.MyMembershipProvider, MyAssembly"/>
  </providers>
</membership>

Membership Provider

public class MyMembershipProvider : MembershipProvider
{
    private IMyService myService;

    public MyMembershipProvider() : base()
    {
        // We should use constructor injection here but since we cannot control
        // the construction of this class, we're forced to create the dependency
        // ourselves.
    }

    public override bool ValidateUser(string username, string password)
    {
        if (myService == null)
        {
            // This scope is only reached once within the browser session,
            // ASP.NET keeps the instance of MyMembershipProvider in memory
            // so the myService field keeps its value across web requests.
            // This results in Castle Windsor (which I have configured the service
            // locator to use) not being able to control the lifetime of
            // the MyService instance. So, the inability of Windsor to control
            // the lifetime of MembershipProvider instances, inhibits the lifetime
            // management of MyService instances as well.
            myService = ServiceLocator.Current.GetInstance<IMyService>();
        }

        return myService.ValidateUser(username, password);
    }
}
  • 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-18T05:04:59+00:00Added an answer on May 18, 2026 at 5:04 am

    I just blogged about this with a solution.

    In a nutshell, this solution involves a simple, reusable MembershipProvider that calls the container to resolve your custom MembershipProviders. Unlike other solutions that use “BuildUp” container features, this one takes true control of instantiation, thus enabling constructor injection (which in turn enables immutability) and proxyability.

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

Sidebar

Related Questions

I have a custom configuration section registered in the app/web.config, let's call it MySection
I have a Custom Control registered in the page using this code: <%@ Register
I have a custom WPF control base class. This base class registers a custom
My application has custom Role and MembershipProviders. I've registered them in web.config, but when
i have a custom behavior extension which i'm using in my client side app.config
I have a custom control and it's been registered in main page in a
In a VS Package (Visual Studio Extensibility), I have a custom extension registered (for
I have multiple custom controls used on a ASPX (and C#) page registered from
I have registered an enumeration type ClefType within my header file - this enum
I have a table of recent web guest who have registered. One of the

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.