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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:32:18+00:00 2026-05-13T10:32:18+00:00

I am currently using Autofac, but am open to commentary regarding other IOC containers

  • 0

I am currently using Autofac, but am open to commentary regarding other IOC containers as well. I would prefer a solution using Autofac if possible. I am also somewhat new to IOC so I may be grossly misunderstanding what I should be using an IOC container for.

Basically, the situation is as follows:

I have a topmost IOC container for my app. I have a tree of child containers/scopes where I would like the same “service” (IWhatever) to resolve differently depending on which level in the tree it is resolved. Furthermore if a service is not registered at some level in the tree I would like the tree to be transversed upward until a suitable implementation is found.

Furthermore, when constructing a given component, it is quite possible that I will need access to the parent container/scope. In many cases the component that I’m registering will have a dependency on the same or a different service in a parent scope.

Is there any way to express this dependency with Autofac? Something like:

builder.Register(c=>
{
   var parentComponent = ?.Resolve<ISomeService>();
   var childComponent = new ConcreteService(parentComponent, args...);
   return childComponent;
}).As<ISomeService>();

I can’t get anything similar to the above pseudocode to work for several reasons:

A) It seems that all levels in the scope tree share a common set of registrations. I can’t seem to find a way to make a given registration confined a certain “scope”.

B) I can’t seem to find a way to get a hold of the parent scope of a given scope. I CAN resolve ILifetimeScope in the container and then case it to a concrete LifetimeScope instance which provides its parent scope, but I’m guessing it is probably note meant to be used this way. Is this safe?

C) I’m not sure how to tell Autofac which container owns the resolved object. For many components I would like component to be “owned” by the scope in which it is constructed. Could tagged contexts help me here? Would I have to tag every level of the tree with a unique tag? This would be difficult because the tree depth is determined at runtime.

Sorry for the extremely lengthy question. In summary:

1) Is there any way to do what I want to do using Autofac?

2) Is there another container more suited to this kind of dependency structure?

3) Is IOC the wrong tool for this altogether?

  • 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-13T10:32:19+00:00Added an answer on May 13, 2026 at 10:32 am

    Autofac 1.4 supports this easily and is probably the best choice here right now. You can simply register the child container components in the child container.

    Autofac 2, which you’re using, doesn’t have a simple equivalent yet, although it is being investigated.

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

Sidebar

Related Questions

We're currently following the DI model using Autofac as an IoC container. We've recently
I am currently using/experimenting with autofac as my IoC controller. Previously to this I
Currently using Google Analytics as a supplement to our paid tracking software, but neither
I'm currently using a Camera Chooser on my app, but want my user to
Is anyone currently using StreamInsight (other than just demoing)? If so, how is it
I'm currently doing a bit of experimenting using Autofac-1.4.5.676, autofac contrib and castle DynamicProxy2.
Currently using: @^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;%\$#_]*)?$ How can i make http:// not compulsory but if it does
Im currently using a plugin called Cycle for jQuery and would like to tweak
Im currently using a UITableView like any other, and I am researching into the
I am currently using matplotlib.pyplot to create graphs and would like to have 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.