1

I am implementing a custom ASP.NET membership provider that operates based on the custom repository class that in turn uses an Entity Framework DbContext as a mean of accessing a data.

Since this is an ASP.NET MVC application, IoC container (Ninject) is set to resolve instances of my DbContext InRequestScope.

My user data tables are a part of the single main DbContext.

Repository class is also bound to instantiate in InRequestScope. But the repository class is created by to satisfy the need of the custom MembershipProvider, which can't be set to instantiate InRequestScope. As a result, whenever I am trying to access Role data via repository, I get DbContext is already disposed exception.

Has anyone set up a similar configuration and if so, what was implemented differently to overcome the problem I am having. Thanks.

Maxim V. Pavlov
  • 10,303
  • 17
  • 74
  • 174
  • Similar questions [here](http://stackoverflow.com/questions/1003587/how-to-integrate-ioc-membership-provider-with-asp-net-mvc) and [here](http://stackoverflow.com/questions/1551503/dependency-injection-and-asp-net-membership-providers) – Eranga Aug 22 '12 at 04:12

1 Answers1

0

A workaround that has allowed me to continue with the project development was to manually create an instance of DbContext in Membership Provider constructor, in contrast to have Ninject inject it.

Maybe someone eventually will come up with a better approach to this particular problem, please post it here and I will remark it as an answer instead of this workaround.

Maxim V. Pavlov
  • 10,303
  • 17
  • 74
  • 174
  • Have just stumbled upon my own question and still my answer works fine. Probably somethin wrong with my Repo lifetime management. – Maxim V. Pavlov Nov 05 '12 at 15:27