Dependency Injection with Custom Membership Provider

Posted by alastairs on Stack Overflow See other posts from Stack Overflow or by alastairs
Published on 2010-05-02T12:19:44Z Indexed on 2010/05/02 12:27 UTC
Read the original article Hit count: 640

I have an ASP.NET MVC web application that implements a custom membership provider. The custom membership provider takes a UserRepository to its constructor that provides an interface between the membership provider and NHibernate. The UserRepository is provided by the Ninject IoC container.

Obviously, however, this doesn't work when the provider is instantiated by .NET: the parameterless constructor does not have a UserRepository and cannot create one (the UserRepository requires an NHibernate session be passed to its constructor), which then means that the provider cannot access its data store. How can I resolve my object dependency?

It's probably worth noting that this is an existing application that has been retrofitted with Ninject. Previously I used parameterless constructors that were able to create their required dependencies in conjunction with the parametered constructors to assist unit testing.

Any thoughts, or have I built myself into a corner here?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-mvc