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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:33:19+00:00 2026-06-14T17:33:19+00:00

Entity Framework 4, Ninject 3, MVC3 Currently in my web app i have been

  • 0

Entity Framework 4, Ninject 3, MVC3
Currently in my web app i have been using a rather rudimentary approach to per request instantiation of an Object Context. So I am experimenting with Ninject, and some old sample code, but I am unsure how to proceed with the following..
Effectively I want to be able in the controller to do the equivalent of: DB_Entities.Current.Albums … Should i be instantiating a StandardKernel every time?
The sample i was looking at was using the following: MvcApplication.Container.Get(); but in Ninject 3 with the App_Start hookup I dont have access to Container..

My attempt to replicate the above line, is failing at runtime.

using MusicStoreEntities;
using Ninject;
using TestMVC3WithIOC.App_Start;
using System.Data.Objects;

namespace TestMVC3WithIOC.Models
{
    public partial class MusicStoreEntities
    {
        public static MusicStoreEntities Current
        {
        get
        {
            using (IKernel kernel = new StandardKernel())
            {
            return (MusicStoreEntities)kernel.Get<ObjectContext>();
            }
        }
        }
    }
}

Also, note, that in App_Start\NinjectWebCommon.cs I have the following modification:

    private static void RegisterServices(IKernel kernel)
    {
        kernel.Bind<ILogger>().To<NLogger>();
        kernel.Bind<ObjectContext>().To<MusicStoreEntities>().InRequestScope();

    } 
  • 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-06-14T17:33:20+00:00Added an answer on June 14, 2026 at 5:33 pm

    Although a workable solution, it seems ill-advised to pass the entire Kernel into a class, because it tends to obscure the classes actual, specific dependencies. A better approach is to pass a factory dependency into your controller’s constructor.

    public partial class MusicStoreEntities
    {
        private readonly IEntitiesFactory _factory;
    
        public MusicStoreEntities(IEntitiesFactory factory)
        {
            _factory = factory;
        }
    }
    

    IEntitiesFactory has a simple implementation with a single method GetObjectContext().


    (I believe also the “Unit of Work” pattern is popular at the moment, but I can’t really speak to that as I haven’t used it. Maybe worth looking into.)

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

Sidebar

Related Questions

I have a MVC3 project that uses the Entity Framework and Ninject v2.2, and
I am using: Asp.net MVC3 Ninject Repository pattern with Entity Framework 4.0 On an
I have been using Ninject IoC container in my ASP.NET MVC3 portal. Whenever I've
Using Entity Framework Code First, the web application crashes on a call to DbContext
Using Entity Framework I have the fields: o CreatedOn (datetime) o CreatedBy (nvarchar(50)) o
I'm using Entity Framework 4, Ninject, and Moq throughout my projects. When I get
I'm working on an MVC site with Entity Framework Code First, using Ninject for
I am building a .NET 4.0 MVC3 app. I use Entity Framework 4.1 and
Using Entity Framework 4.1 with SQL Server 2008 R2 Express. I have a strongly
Using Entity Framework 4.1 I have the following tables I'm using with Entity Framework

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.