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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:05:33+00:00 2026-05-30T20:05:33+00:00

I am creating an ASP.NET MVC 3 e-commerce website and I am currently working

  • 0

I am creating an ASP.NET MVC 3 e-commerce website and I am currently working on the admin area where you can add/edit products. To create the UI for the product page I am using Telerik MVC controls.

My problem is that when I added a second telerik grid which both retrieve data from the database through an ajax call I receive a couple different errors listed below:

{“There is already an open DataReader associated with this Command
which must be closed first.”}

{“The connection was not closed. The connection’s current state is
connecting.”}

Database Context Code

public interface IUnitOfWork
{
    void Commit();
}

public class GSPDataContext : DbContext, IUnitOfWork
{
    /* (omitted) IDbSet's for entities */
    public GSPDataContext()
      : base("GSPConnectionString")
    {

    }

    public virtual IDbSet<T> DbSet<T>() where T : class
    {
       return Set<T>();
    }

    public virtual void Commit()
    {
        base.SaveChanges();
    }
}

Generic Repository Code

public class Repository<T> : IRepository<T> where T : class
{
    private GSPDataContext m_dataContext;
    private readonly IDbSet<T> m_entity;

    public Repository(GSPDataContext dataContext)
    {
        if (dataContext == null)
            throw new ArgumentException();

        m_dataContext = dataContext;

        m_entity = m_dataContext.Set<T>();
    }

    public T GetById(int id)
    {
        return this.m_entity.Find(id);
    }

    public void Insert(T entity)
    {
        if (entity == null)
            throw new ArgumentException();

        this.m_entity.Add(entity);

        //this.m_dataContext.SaveChanges();
    }

    public void Delete(T entity)
    {
        if (entity == null)
            throw new ArgumentException();

        this.m_entity.Remove(entity);

        //this.m_dataContext.SaveChanges();
    }

    public virtual IQueryable<T> Table
    {
        get
        {
            return this.m_entity;
        }
    }
}

Ninject Code

private static void RegisterServices(IKernel kernel)
    {
        //Customer
        kernel.Bind<IAddressValidationService>().To<AddressValidationService>().InRequestScope();
        kernel.Bind<ICustomerService>().To<CustomerService>().InRequestScope();
        kernel.Bind<ICustomerProductService>().To<CustomerProductService>().InRequestScope();

        //Authentication
        kernel.Bind<IOpenIDLoginService>().To<OpenIDLoginService>().InRequestScope();
        kernel.Bind<IAuthenticationService>().To<FormsAuthenticationService>().InRequestScope();

        //Products
        kernel.Bind<IProductService>().To<ProductService>().InRequestScope();
        kernel.Bind<IRecentlyViewedProductService>().To<RecentlyViewedProductService>().InRequestScope();
        kernel.Bind<IProductPictureService>().To<ProductPictureService>().InRequestScope();
        kernel.Bind<ICategoryService>().To<CategoryService>().InRequestScope();
        kernel.Bind<IPictureService>().To<PictureService>().InRequestScope();

        //Shopping Cart
        kernel.Bind<IShoppingCartService>().To<ShoppingCartService>().InRequestScope();

        //Shipping and Payment
        kernel.Bind<IShippingService>().To<ShippingService>().InRequestScope();
        kernel.Bind<IPaymentService>().To<PaymentService>().InRequestScope();

        //Orders
        kernel.Bind<IOrderCalculationService>().To<OrderCalculationService>().InRequestScope();
        kernel.Bind<IOrderProcessingService>().To<OrderProcessingService>().InRequestScope();
        kernel.Bind<IOrderService>().To<OrderService>().InRequestScope();

        //
        kernel.Bind<IEncryptionService>().To<EncryptionService>().InRequestScope();
        kernel.Bind<ILogger>().To<LoggingService>().InRequestScope();
        kernel.Bind<IWebManager>().To<WebManager>().InRequestScope();

        //Messages
        kernel.Bind<IEmailService>().To<EmailService>().InRequestScope();
        kernel.Bind<IMessageTemplateService>().To<MessageTemplateService>().InRequestScope();
        kernel.Bind<IWorkflowMessageService>().To<WorkflowMessageService>().InRequestScope();

        //Data
        kernel.Bind<GSPDataContext>().ToSelf().InSingletonScope();
        kernel.Bind<IUnitOfWork>().ToMethod(ctx => ctx.Kernel.Get<GSPDataContext>()).InSingletonScope();
        kernel.Bind(typeof (IRepository<>)).To(typeof (Repository<>)).InRequestScope();

        kernel.Bind<IWorkContext>().To<WebWorkContext>().InRequestScope();
    }

I suspect it has something to do with how ninject is managing the lifetimes of the various services, but I am not sure what I need to do to make it work.

Any advice would be much appreciated.

Thanks

UPDATE

According to Remo’s comment I change my code to the following:

//Data
    kernel.Bind<GSPDataContext>().ToSelf().InRequestScope();
    kernel.Bind<IUnitOfWork>().ToMethod(ctx => ctx.Kernel.Get<GSPDataContext>()).InRequestScope();
    kernel.Bind(typeof (IRepository<>)).To(typeof (Repository<>)).InRequestScope();

And I am now getting the following error:

The ObjectContext instance has been disposed and can no longer be used
for operations that require a connection.

Any ideas?

  • 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-30T20:05:34+00:00Added an answer on May 30, 2026 at 8:05 pm

    No, it has nothing to do with how Ninject manages lifetimes. But it has to do how you configured the lifecycles.

    It is important that a new DbContext is used for each request. This has to be InRequestScope.

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

Sidebar

Related Questions

I'm creating an Admin page for my ASP.Net MVC 3 application. I can create
I am currently creating an e-commerce site using C# ASP.NET MVC and have just
I'm creating a ASP.NET MVC website and I was wandering which techniques do you
I am creating an ASP.Net MVC website that I am launching soon in private
I am in the process of creating a website using ASP.NET MVC. I went
I'm creating a Shared (static) method in ASP.NET MVC so it can be used
I'm creating my first ASP.NET MVC 3 website for my company's intranet. It's a
I am creating an Asp.net MVC application and I'm currently using the built in
I'm creating an ASP.Net MVC website. I've to display some text in some modal
I'm creating an Asp.Net MVC website. I've in the past, for heavy application, multiple

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.