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

  • Home
  • SEARCH
  • 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 6893025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:36:27+00:00 2026-05-27T06:36:27+00:00

I setup a CustomRoleProver as: public class CustomRoleProvider : RoleProvider { private readonly IRepository<User>

  • 0

I setup a CustomRoleProver as:

public class CustomRoleProvider : RoleProvider
    {
        private readonly IRepository<User> _repository;

        public CustomRoleProvider(IRepository<User> repository)
        {
            _repository = repository;
        }

...

In my Global.asax.cs I have:

//Create Ninject DI kernel
            var kernel = new StandardKernel();

            kernel.Bind<IRepository<User>>().To<Repository<User>>();

            //Tell ASP.NET MVC 3 to use our Ninject DI Container
            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));

When I try to run my code I get:

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: No parameterless constructor defined for this object.

Source Error:

Line 64:
Line 65:
Line 66:
Line 67:
Line 68:

So maybe I have a totally incorrect understanding of DI and ninject. I thought that when it tried to instantiate teh CustomRoleProvider it would create the user repository and pass it to the constructor not trying to use a parameterless one.

Do I understand this incorrectly or is my setup just incorrect?

I find this strange because the DI seems to be mostly working for the controllers.

  • 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-27T06:36:28+00:00Added an answer on May 27, 2026 at 6:36 am

    You’re writing a roleprovider, but these are not currently DI aware. A lot of the classes in MVC are DI aware, which is why you see it workign with controllers.

    To be able to inject a constructor parameter the DI container has to be responsible for creating the object you’re hoping to inject into. Just registering a type does not magically make it locatable.

    With roleproviders, it is the Roles class within the framework that create instances of the providers, including your custom provider. It only works parameterless constructors. You’ll need to use something like property injection within your custom provider and use Roles.Provider to get the instance to inject your dependencies into.

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

Sidebar

Related Questions

Setup: class A { public: void a() {} }; class B { public: void
Setup public interface ITable { } public class Company : ITable { public int
Setup Have you ever had the experience of going into a piece of code
Setup I have a website that draws RSS feeds and displays them on the
Setup: I have an HTML page with a fieldset element. The background color of
Setup I have a VBScript for driving the stress testing of a web service.
Setup: I have a COM DLL that calls a method inside a managed C#
Setup : I have a Struts web application where I use displaytag elements to
Setup: I have a UITextView inside a UITableViewCell 's contentView . I want it
Setup: I have a combo-box, it's itemsource bound to an ObservableCollection<T> of a custom

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.