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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:13:43+00:00 2026-05-25T10:13:43+00:00

I set up Ninject in my asp.mvc project. And it works fine each controller

  • 0

I set up “Ninject” in my asp.mvc project. And it works fine each controller get its dependency classes. But I have one class in mvc project that is not controller. It’s a simple class that extends “MembershipProvider” (because I have made custom membership) and I need to inject “UserRepository” class in it.
In a NinjectControlelrFactory I bint it:

private void AddBindings()
{
ninjectKernel.Bind<IUserRepository>().To<UserRepository>().WithConstructorArgument(
                "connectionString", ConfigurationManager.ConnectionStrings["connStr"].ConnectionString);
}

But how to get it from non controller class?
PS
I can’t inject through constructor.

I have some solution but I don’t know how ‘clean’ it is:

using (IKernel kernel = new StandardKernel())
            {
                kernel.Bind<IUserRepository>()
                    .To<UserRepository>()
                    .WithConstructorArgument("connectionString", "ttttttttttttt");
                //var tc = kernel.Get<IUserRepository>();
                this.userRepository = kernel.Get<IUserRepository>();
            }
  • 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-25T10:13:44+00:00Added an answer on May 25, 2026 at 10:13 am

    Use Property Injection. Register your MembershipProvider in the Ninject and use Property injection.

    You will need to instantiate MembershipProvider via ninject context.

    Check these articles.

    Property Injection in ASP.NET MVC with Ninject

    Injecting properties in Ninject 2 without ‘Inject’ attribute

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

Sidebar

Related Questions

I have configured Ninject 2 in an ASP.NET 4.0 project (not MVC) however when
I've set up DI with Ninject in my ASP.NET MVC application like this Bind<IRepository>().To<XmlDefaultRepository>().WhenInjectedInto(typeof(PageController)).WithConstructorArgument(contentType,
I have set up ninject on my project in the global.asax file... protected void
I have an asp.net-mvc website and i am using ninject for IOC and nhibernate
I have an ASP.NET MVC 3 application and am using Ninject for injecting dependencies
I have set up a NInject (using version 1.5) binding like this: Bind<ISessionFactory>().ToMethod<ISessionFactory>(ctx =>
I set up 404 handler page in web.config, but it works ONLY when extension
I'm using NInject with NInject.Web.Mvc. To start with, I've created a simple test project
We are using Ninject in our MVC3 project to do dependency injection. I used
I am using asp.net mvc 3, ninject 2.0 and the ninject mvc 3 plugin.

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.