title: ASP.NET MVC 3 Ninject Custom Membership and Role Provider
body: <p>Hi i got some problems enabling custom Membership and Role Provider, i got following error:</p>
  <blockquote>
  <p>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.</p>
  <p>System.InvalidOperationException: Default Membership Provider could not be found.</p>
  </blockquote>
  <p>It's pointing to my mvc3.ninject <code>kernel.Inject(Membership.Provider)</code></p>
  <p><strong>My MVC3.Ninject in app_start:</strong></p>
  <pre><code>private static void RegisterServices(IKernel kernel)
  {
      kernel.Inject(Membership.Provider);
      kernel.Inject(Roles.Provider);
      kernel.Bind&lt;IUnitOfWork&gt;().To&lt;EFContext&gt;().InRequestScope();
      kernel.Bind&lt;IUzytkownicyRepository&gt;().To&lt;UzytkownicyRepository&gt;().InRequestScope();            
  }  
  </code></pre>
  <p><strong>My RoleProvider:</strong></p>
  <pre><code>public class DziennikRoleProvider : RoleProvider
  {
      [Inject]
      private IUzytkownicyRepository repository { get; set;}
  </code></pre>
  <p><strong>My MembershipProvider:</strong></p>
  <pre><code>public class DziennikMembershipProvider : MembershipProvider
  {
      [Inject]
      private IUzytkownicyRepository repository { get; set; }
  </code></pre>
  <p><strong>My WebConfig file:</strong></p>
  <pre><code> &lt;membership defaultProvider=&quot;DziennikMembershipProvider&quot;&gt;
    &lt;providers&gt;
      &lt;clear/&gt;
      &lt;add name=&quot;DziennikMembershipProvider&quot; type=&quot;Dziennik_MVC.Helpers.DziennikMembershipProvider, Dziennik_MVC&quot; connectionStringName=&quot;EFDbContext&quot;
           applicationName=&quot;/&quot; /&gt;
    &lt;/providers&gt;
  &lt;/membership&gt;
  
  &lt;profile&gt;
    &lt;providers&gt;
      &lt;clear/&gt;
    &lt;/providers&gt;
  &lt;/profile&gt;
  
  &lt;roleManager defaultProvider=&quot;DziennikRoleProvider&quot; enabled=&quot;true&quot; cacheRolesInCookie=&quot;true&quot;&gt;
    &lt;providers&gt;
      &lt;clear /&gt;
      &lt;add name=&quot;DziennikRoleProvider&quot; type=&quot;Dziennik_MVC.Helpers.DziennikMembershipProvider, Dziennik_MVC&quot; connectionStringName=&quot;EFDbContext&quot; /&gt;
    &lt;/providers&gt;
  &lt;/roleManager&gt;
  </code></pre>