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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:20:36+00:00 2026-06-05T17:20:36+00:00

I am using Autofac to handle dependency injection in my application. In order not

  • 0

I am using Autofac to handle dependency injection in my application. In order not to have to do every single registration explicitly, I first use RegisterAssemblyTypes().AsImplementedInterfaces() and then only take care of those that need to be specially configured.

I have an interface called IToolStripPopulator that has a few different implementations, several of which are in use, but some aren’t anymore (as I’m trying to work SOLIDly and adhere to OCP, I am usually not changing them if I need different functionality, but rather leave them alone and create new ones that do what I need now). For that reason I need to overwrite the automatic registration for the interface, in two ways:

  • One implementation is to be injected into my main logic and acts as a decorator for a few of the others. I naturally want this to be registered via As<IToolStripPopulator>() and be done with it as this is the implementation my application’s functionality currently depends on.
  • Those other implementations are the “inner” populators only to be used within that decorator class. To inject them, there are two ways:
    • Explicitly wiring up the constructor for the outer implementation with the specific types; this is not very nice, also because that constructor would have to take the exact number of inner populators I am using right now, which is not OCP compliant.
    • Have the outer implementation take an IEnumerable<IToolStripPopulator>; this is what I’d like to do, but it’s also where I’m stuck.

I can’t let Autofac resolve that IEnumerable on its own, because it would just resolve all implementations of the interface, even those that I’m not using anymore as well as the “outer” that I don’t want in there (and which would probably cause an endless loop during resolution).

So what I’d like to do is this:

// the inner populators
builder.RegisterType<BrowsersMenuPopulator>().Named<IToolStripPopulator>("inner");
builder.RegisterType<ThreadsafeConnectionMenuPopulator>().Named<IToolStripPopulator>("inner");

// the decorator implementation
builder.RegisterType<BrowserAndConnectionMenuPopulator>().As<IToolStripPopulator>().WithParameter( ? );

But there is no way to actually access the existing registrations at that point.

  • 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-05T17:20:38+00:00Added an answer on June 5, 2026 at 5:20 pm

    ….and here I tried just one more thing which I didn’t actually expect to work, but it did.

    builder.Register(c => c.ResolveNamed<IEnumerable<IToolStripPopulator>>("inner")).As<IEnumerable<IToolStripPopulator>>();
    

    does not, as I would have expected, try to resolve an IEnumerable<IToolStripPopulator> registration named “inner”, but an IEnumerable of IToolStripPopulator registrations named “inner” – exactly as I need it.

    This will then correctly be resolved and injected into the decorator implementation just from having that registered As<IToolStripPopulator>() with no further configuration.

    From a formal aspect I would actually have preferred being able to state the name by which to resolve directly with the decorator registration because that would be more intuitive and flexible (what if I need to resolve several IEnumerable<IToolStripPopulator>?), but in many cases this should be enough.

    @codinghorror’s concept of “rubber duck problem solving” rules my every workday….

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

Sidebar

Related Questions

I'm using Autofac to handle dependency injection in my application. However, I have one
I am using Autofac 2.1.12 to handle my dependency injection, and am having trouble
I have started to use Autofac following this tutorials: http://flexamusements.blogspot.com/2010/09/dependency-injection-part-3-making-our.html Simple class with no
I'm using Autofac. I want to inject a different implementation of a dependency based
What is the best approach to managing NHibernate transaction using Autofac within web application?
I'm using Castle DynamicProxy with Autofac. I have an object for which I've created
I'm trying to autowire up my application using Autofac. All is fine apart from
I have run into an issue while creating a data service and using Autofac
I have an MVC3 app using Autofac and a custom membership provider. If I
I have been using autofac with MVC 3 for a while and love it.

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.