How to integrate IoC Membership provider with ASP.NET MVC

The simplest way to get this to work is to use ASP.NET’s standard mechanism of <membership> in web.config. You just let it use the default constructor but you override Initialize() and pull the dependencies there. Use this as reference.

Personally, due to things like this, I prefer to avoid the provider model altogether so I use an approach similar to the ones described in the MonoRail docs. IMHO it’s less bloated and more flexible. In the end, it’s just about setting HttpContext.User with a proper IPrincipal implementation which is what the AuthorizeAttribute uses.

I recently blogged about a solution to do proper IoC with MembershipProviders.

Leave a Comment