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 7447577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:39:17+00:00 2026-05-29T12:39:17+00:00

I am aware that a thousand and one questions relating to this topic have

  • 0

I am aware that a thousand and one questions relating to this topic have been asked, but I have gone through at least a dozen and am still not connecting the dots. I am trying to setup dependency injection for entity contexts.

I have always created my entity context as I have seen in the MS tutorials, like so:

public class UserController : Controller
{
    private DbEntities db = new DbEntities();

}

Recent reading has told me that this is no longer (if it ever was) the best practice, and a dependency injection method should be used. Ninject is mentioned often, but I am seeing how you move from what I have, to the example give in the Ninject documentation.

It should look like this when I am done, right?

public class UserController : Controller
{
    private DbEntities db;

    public UserController(DbEntities context)
    {
        db = context;
    }
}

The documentation starts out with “In the previous step we already prepared anything that is necessary for controller injection.” which is confusing as hell, since the previous step was installation. I used the Nuget method to install, but I don’t know what it means when it says “Now load your modules or define bindings in RegisterServices method.” How do I do that, and is entity a module or a binding? The documentation feels so sparse.

I am sorry if I skipped over something critical in the docs, I’ve been bouncing between forums for hours trying to figure out this one step.

  • 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-29T12:39:17+00:00Added an answer on May 29, 2026 at 12:39 pm

    I used the Nuget method to install, but I don’t know what it means
    when it says “Now load your modules or define bindings in
    RegisterServices method.” How do I do that, and is entity a module or
    a binding?

    The Nuget installation actually does quite a lot of things for you already. The most important thing is that it sets up Ninject as controller factory, which means that Ninject will create your controllers and is able to pass in all dependencies you have registered with it.

    If you check the App_Start folder you will find a file NinjectMVC3.cs. There is already an empty method RegisterServices() which you can use to register your dependencies.

    For your example you must be able to resolve DbEntities. The easiest most basic way to do this is:

    kernel.Bind<DbEntities>().ToSelf();
    

    That said you really should pass in an interface to your controller so the controller does not depend on Entity Framework, using abstractions and registering a concrete class to use in the IoC container is one of the main reasons for dependency injection.

    This should give you a start – the documentation you link to seems a bit outdated. I would recommend looking at the Ninject MVC3 sample on github.

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

Sidebar

Related Questions

I am aware that this topic has been covered already in many places, but
I aware that this will be a less programming question, but still... How can
I am aware that this is a more subjective question than is preferred, but
I am aware that this is somewhat a re-post, but I feel like re-posting
I'm fully aware that set division can be accomplished through a series of other
I am aware that you can lock an object in c# using lock but
I'm aware of the normal causes of this issue, but what's wrong with this
I have two vectors with a few thousand points, but generalized here: A <-
I was made aware that ilmerge is a console application but when I run
I'm not aware of tools that are being developed for java, but i think

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.