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

The Archive Base Latest Questions

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

Just started playing with ninject – and I can’t get past this issue. Consider

  • 0

Just started playing with ninject – and I can’t get past this issue. Consider this setup:

private static void RegisterServices(IKernel kernel)
{
   kernel.Bind<IDataTransaction>().To<DataTransaction>().InRequestScope();

   kernel.Bind<IdbAnalytics>().To<dbAnalytics>().InRequestScope();
   kernel.Bind<IdbMembership>().To<dbMembership>().InRequestScope();

   kernel.Bind<IAnalyticsWork>().To<AnalyticsWork>().InRequestScope();
   kernel.Bind<IMembershipWork>().To<MembershipWork>().InRequestScope();

   kernel.Bind<ILog>().To<Log>().InRequestScope();
   ...
}

With Log being injected into the above classes:

public class AnalyticsWork : IAnalyticsWork, IDisposable
{
    private readonly IdbAnalytics _Context;
    private readonly ILog _Log;

    public AnalyticsWork(IdbAnalytics Context, ILog Log)
    {            
        _Context = Context;
        _Log = Log;
        _Log.Write(LogEntryType.DEBUG, "Object Created");
    }
    ...
}

This issue is the Log object gets disposed of ahead of the other objects (AnalyticsWork / MembershipWork). Is there any way to set the order that items should be disposed of? Or is this setup flawed?

  • 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:34:41+00:00Added an answer on June 8, 2026 at 1:34 am

    I do not use NInject, but it sounds to me that you are registering the Log concrete as shared or per web request (as per the InRequestScope might indicate, again I do apologize for not using NInject so I am not sure what that does).

    For all of the loggers I’ve used, NLog, Log4Net, MS’ Logging Application Block, etc – they all require Transient registration, not Scoped, because they take the superclass that initiated them to write out in the log as the calling class.

    As far as dispose order, I don’t think you can control that with any IoC container because the object cannot be disposed in different orders if another class still has a reliance. I ran into the same issues when I first started with IoC Containers years ago and thought, “Yeah, I’ll register everything as scoped!” Hehe, that didn’t work out very well.

    I would say your objects just need to be registered differently. Only scope the items you really need scoped, everything else as transients or singletons. I usually follow the pattern of:

    Code everything singleton and code thread-safe.
    If not thread-safe make it a transient and register it as such.

    If I not using a unit-of-work pattern with my ORM, I will typically register my ORM containers as Scoped so they can track the object changes for the life of the request, and SaveChanges() latter (e.g. Entity Framework 4, or NHibernate’s Session, etc).

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

Sidebar

Related Questions

I've just started playing around with Kickstrap and I can't get the build script
I just started playing around with MSBuild this evening and am porting an nAnt
I just started playing with the Google Map API for Static Images, and in
I've just started playing with IoC containers and therefore chosed Ninject. After several hours
I just started playing around with XSLT and PHP. However what I can't figure
I've just started playing with ssh on Mac. I want to setup ssh port
I just started playing with Selenium and I ran into an issue. I have
Just started playing with Geolocation. And I see that you get a request (at
I just started playing around with JSON and I have created this example. var
Just started playing around with ice_cube I've got a weekly schedule (with a granularity

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.