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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:07:56+00:00 2026-05-28T08:07:56+00:00

Specifically, if I use NInject to create a bunch of objects that have been

  • 0

Specifically, if I use NInject to create a bunch of objects that have been bound in singleton scope, I expect NInject to release them in reverse order.

I have a test case as follows, I want to know if I am doing something wrong, or if NInject2 has a bug.

I expect to see that, given that I have created an instance of Foo, and then an instance of Bar, NInject should be releasing Bar before it releases Foo! Why isn’t it doing this?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ninject;

namespace ConsoleApplication1
{
    interface IFoo
    {
    }

    interface IBar
    {
    }

    class Foo : IFoo, IDisposable
    {
        public Foo()
        {
            System.Console.WriteLine("Created Foo Instance");
        }
        public void Dispose()
        {
            System.Console.WriteLine("Disposed Foo Instance");
        }
    }

    class Bar : IBar, IDisposable
    {
        public Bar(IFoo foo)
        {
            System.Console.WriteLine("Created Bar Instance");
        }
        public void Dispose()
        {
            System.Console.WriteLine("Disposed Bar Instance");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            using (var kernel = new Ninject.StandardKernel())
            {
                kernel.Bind<IBar>().To<Bar>().InSingletonScope();
                kernel.Bind<IFoo>().To<Foo>().InSingletonScope();

                kernel.Get<IFoo>();
                kernel.Get<IBar>();
            }
        }
    }
}

Actual output:

Created Foo Instance
Created Bar Instance
Disposed Foo Instance
Disposed Bar Instance

Expected output:

Created Foo Instance
Created Bar Instance
Disposed Bar Instance
Disposed Foo Instance
  • 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-28T08:07:58+00:00Added an answer on May 28, 2026 at 8:07 am

    Ninject doesn’t have reference counting at the moment. Therefore the instances are disposed in any order. If you want this you would have to write a ICache implementation which has reference counting.

    Alternatively you can use define that Foo is in the scope of Bar using named scope. This will ensure that Foo won’t be disposed before Bar.

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

Sidebar

Related Questions

I have a set of php pages that I use specifically for AJAX requests.
We have an application which needs to use Direct3D. Specifically, it needs at least
[Assignment] Requirement Use specifically OutputStream subclasses to output data to a .txt file, that
How to use binder2nd, bind2nd, and bind1st? More specifically when to use them and
I have a dialog box that allows users to set hotkeys for use in
I am trying to use Ninject to implement cascading injection into a class that
I am working on an application that monitors phone use (specifically, what time its
I want to keep my website/s in version control (Subversion specifically) and use svn
I'm attempting to use QtWebKit (specifically, a QWebView widget) to display a web page
A good example of when exactly to use interfaces specifically in Java would be

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.