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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:10:53+00:00 2026-05-29T06:10:53+00:00

Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();

  • 0

Here is an example.

foreach (var doc in documents)
{
    var processor = this.factory.Create();
    processor.Process(doc);
}

The factory internally calls kernel.Get<IDocumentProcessor>().

I’d like all the document processor’s dependencies’ lifetimes to be “scoped” to this composition root. This configuration seems to do what I want:

kernel.Bind<IEntityContext>().To<EntityContext>().InCallScope();

Now each object graph rooted at the document processor has a unique, shared entity context for accessing the database. But this

  1. affects all entity contexts everywhere in the application (which may be ok, but seems hard to discover), and
  2. only seems to work for bindings known about statically.

I think my question is, how can I achieve the same scoping / lifetime management effect with “contextual” or dynamic information? Perhaps I want to have the document instance itself injected into all children of the new root:

    var processor = this.factory.Create(doc)
    processor.Process()

Thanks!

  • 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-29T06:10:54+00:00Added an answer on May 29, 2026 at 6:10 am

    With Ninject 3.0.0 you can do

    kerne.Get<IProcessor>(new ConstructorArgument("doc", doc, true));
    

    But to me there still seems to be a design flaw to have doc as a dependency of the processor. It would be better to create the processor once and reuse it for multiple documents by passing the document to the Process method. I still do not get what’s the issue with this due to the fact that the question does not show the actual problem.

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

Sidebar

Related Questions

The fictional example here. Suppose I designed a class named IODevice. This class already
This problem is not readily reproducible in a simple example here but was wondering
What does this do? I find the example here, but other than what it
Here is an example of what I've got going on: CREATE TABLE Parent (id
Here is an example of polymorphism from http://www.cplusplus.com/doc/tutorial/polymorphism.html (edited for readability): // abstract base
I have found this example on StackOverflow: var people = new List<Person> { new
Here is my code: foreach (var columnData in lookup.DataProvider.Metadata) { DataGridColumn column = new
Here's a simple method with a foreach loop: IEnumerable<XElement> FieldsToXElements(object instance) { var fieldElements
This question is related to my earlier question, asked here: How do I get
I found a great C++/ODBC example here ... The project I downloaded builds great

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.