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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:22:11+00:00 2026-06-08T01:22:11+00:00

I am using Ninject to use the same database connection per request. We have

  • 0

I am using Ninject to use the same database connection per request. We have a route called RosterProcess that is another web application inside the root, but using the same code base so we can have two different application pools. I believe the application pools are causing an issue with threading since we are throwing some threads during this process. InThreadScope works, but that opens multiple connections in the database instead of using just one. I am getting the error below and not sure why?

Global.asax

kernel.Bind<IDatabaseFactory>().To<DatabaseFactory<MySqlConnection>>().InRequestScope().WithConstructorArgument("connectionString", Config.Data.MySQLConnection);

Factory

public class DatabaseFactory<T> : Disposable, IDatabaseFactory where T : IDbConnection, new()
    {
        private readonly string _connectionString;
        private  IDbConnection _dataConnection;

        public DatabaseFactory(string connectionString)
        {
            _connectionString = connectionString;
        }

        #region IDatabaseFactory Members

        public IDbConnection Get()
        {
            return _dataConnection ?? (_dataConnection = new T { ConnectionString = _connectionString });
        }

        #endregion

        protected override void DisposeCore()
        {
            if (_dataConnection != null)
                _dataConnection.Dispose();
        }
    }

Object reference not set to an instance of an object. at
MySql.Data.MySqlClient.MySqlDataReader.Close() at
MySql.Data.MySqlClient.MySqlConnection.Close() at
MySql.Data.MySqlClient.MySqlConnection.Dispose(Boolean disposing) at
System.ComponentModel.Component.Dispose() at
CL.NatGeo.Dashboard.Data.Infrastructure.DatabaseFactory1.DisposeCore()
at CL.NatGeo.Dashboard.Data.Infrastructure.Disposable.Dispose() at
Ninject.Activation.Strategies.DisposableStrategy.<Deactivate>b__0(IDisposable
x) at Ninject.Activation.InstanceReference.IfInstanceIs[T](Action
1
action) at
Ninject.Activation.Strategies.DisposableStrategy.Deactivate(IContext
context, InstanceReference reference) at
Ninject.Activation.Pipeline.<>c_DisplayClass6.b_4(IActivationStrategy
s) at
Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[T](IEnumerable1
series, Action
1 action) at
Ninject.Activation.Pipeline.Deactivate(IContext context,
InstanceReference reference) at
Ninject.Activation.Caching.Cache.Forget(CacheEntry entry) at
Ninject.Activation.Caching.Cache.Forget(IEnumerable1 cacheEntries) at
Ninject.Activation.Caching.Cache.Clear(Object scope) at
Ninject.OnePerRequestModule.<>c__DisplayClass5.<DeactivateInstancesForCurrentHttpRequest>b__3(ICache
cache) at
Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[T](IEnumerable
1
series, Action`1 action) at
Ninject.OnePerRequestModule.DeactivateInstancesForCurrentHttpRequest()
at Ninject.OnePerRequestModule.b__0(Object o, EventArgs e) at
System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)

  • 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-08T01:22:13+00:00Added an answer on June 8, 2026 at 1:22 am

    Sounds to me like one of your threads thats spawning during the request is attempting to use the database connection – however that connection is already disposed of thanks to Ninject (InRequestScope).

    My suggestion is to rethink your architecture. You’ve fallen into the trap of some high level Sequential Cohesion, in that you’re expecting things to happen in a certain order; but as soon as you start spawning threads you’ll never be able to guarantee what order things are happening in. What makes the request take so long you’ve decided to spawn a thread to take care of it? Can that be improved? Is there really a bottleneck by having more than 1 database connection happen?

    This also explains why you’re seeing results using the InThreadScope binding – Ninject is keeping a database factory per thread you spawn.

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

Sidebar

Related Questions

I have a few classes that are instantiated using ninject Session Scoping - because
Specifically, if I use NInject to create a bunch of objects that have been
I am using Ninject for DI. I have Ninject Modules that bind some services
I am building a MVC3 app using Ninject framework. I have a service that
I have an MVC application using Ninject to connect to a single database. Now
I'm using Ninject 3.0.1.10 for dependency injection and want to use Ninject.Extensions.Logging 3.0.1.0 for
I am using Ninject in my ASP MVC 3 project, I have modified the
I have set up a NInject (using version 1.5) binding like this: Bind<ISessionFactory>().ToMethod<ISessionFactory>(ctx =>
I am using Ninject in MVC3 application. One of my resolvable dependencies makes use
Is there a way to use Property Injection in Ninject 2 without using the

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.