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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:42:58+00:00 2026-06-01T11:42:58+00:00

I would appreciate suggestions as to how to implement the following with Ninject: I

  • 0

I would appreciate suggestions as to how to implement the following with Ninject:

I have a multi-threaded application. It runs approximately 20 very independent threads concurrently. Upon the application startup, I bind an interface to an object via Ninject by using InThreadScope() and all works well. Each thread receives object specific to its thread (constructor of each object instantiates a number of thread-specific flags).

Most of the work that each thread does, is waiting for data-storage to finish process. So, in order to optimize the threads even further, we’ve implemented Parallel.ForEach logic inside the main 20 threads. I would like for threads generated by Paralell.ForEach to get the same binding as their parent thread. However, I cannot simply re-bind the interface to appropriate object inside the Parallel.ForEach, I simply do not know what the bound object is – inside Paralell.ForEach I can only work with the interface.

What’s the proper way to retrieve bindings from the Kernel at runtime, before Paralell.ForEach starts and re-bind them generically inside the loop?

Edit: attempting to include detailed logic/pseudocode:

Each thread once started does something like this:

Kernel.Bind<ILoggingContext>().To<Application1LoggingContext>().InThreadScope();

However, when Parallel.ForEach() kicks in, from inside the individual threads, I no longer have access to Application1LoggingContext object and cannot rebind the ILoggingContext to it. This is because the Parallel.ForEach() is running from a base class and knows not what Application LoggingContext it needs to be bound to. That is done inside each application, upon starting of the big 20 threads.

I’d like to modify the base class, the one that spins up Parallel.ForEach() and ensure inside of each newly created by Parallel.ForEach thread, that ILoggingContext is still bound to Application1LoggingContext – generically, so that I can perform the following:

var ctx = Kernel.Get<ILoggingContext>();
  • 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-01T11:42:59+00:00Added an answer on June 1, 2026 at 11:42 am

    Looks like I’ve figured this out. Here is a generic way to rebind a binding inside Parallel.Foreach. Depending on the complexity/number of bindings, this may or may not work for you out of the box

    var logBinding = Kernel.GetBindings(typeof(ILoggingContext)).FirstOrDefault();
    
    Parallel.ForEach(items, n =>
                                {
                                    if (Kernel.GetBindings(typeof(ILoggingContext)).Count() == 0 && logBinding != null)
                                        Kernel.AddBinding(logBinding);
    
                                    //do stuff
                                    }
                                });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following flow in my application and dont know how to implement
I would appreciate some help with something I working on and have not done
I'm relatively new to Java and would appreciate any help on this! I have
I think I have a conceptual misunderstanding and would appreciate an explanation. Within a
I have a problem finding references to this subject and would appreciate some help.
I would appreciate any help on this issue. Lets say I want to load
I would appreciate some help with an UPDATE statement. I want to update tblOrderHead
I would appreciate some help on creating the proper SQL to retrieve only one
I am a Java beginner and I would appreciate it if someone here can
I'm having a problem with a pesky linker error and would appreciate tips to

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.