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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:43:51+00:00 2026-05-22T00:43:51+00:00

I’m using Ninject with an MVC app, also using EF4.1 Code First. I’m getting

  • 0

I’m using Ninject with an MVC app, also using EF4.1 Code First. I’m getting a problem when trying to test that I can make a request from two different browser instances.

Basically, if I hit login on both browsers at roughly the same time I get an error telling me that “The context cannot be used while the model is being created.”

Now, my first assumption is that I have conflicting instances and am therefore not correctly setting the scope on the contexts.

I have a base class context that contains necessary tables, I inherit from this. I then have a factory that is injected, and is responsible for actually creating the context when I request my repository.

public class ContextFactory
{
     TContext Create<TContext>( ) 
}

I need to do this as my connection string is decided at run-time, so I I can’t just use the connection string contained in the web.config

public class Repository : BaseRepository<MyObject>
{
   public Repository(IContextFactory factory) : base(factory) 
   {
   }
}

The idea being that when I need my repository, I inject the repository, it’s has it’s own injection, creates its context and I can provide some default implementation.

My next concern is that I’m not correctly closing or destroying some instances. I have used someone elses example for setting certain object data in session scope, but most I try and use OnRequestScope.

  • 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-22T00:43:52+00:00Added an answer on May 22, 2026 at 12:43 am

    It sounds like your ContextFactory needs to be bound InRequestScope:

    Bind<IContextFactory>().To<ContextFactory>().InRequestScope();
    

    The error you are receiving seems to indicate that both requests – one from each browser instance – are trying to use the same exact instance of your EF Context, which of course will not work.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
In order to apply a triggered animation to all ToolTip s in my app,
Does anyone know how can I replace this 2 symbol below from the string
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.