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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:12:43+00:00 2026-06-04T04:12:43+00:00

Lets say I have EmailService which implments IEmailService. And EmailService has constructor dependency on

  • 0

Lets say I have EmailService which implments IEmailService. And EmailService has constructor dependency on ILoggingService. Now given that I have several implementations of ILoggingService, can achieve something like this:

<component service="IEmailService, MyInterfaces" type="EmailService, MyLib">
  <parameters>
    <parameter name="loggingService" value="LoggingService, MyLib" />
  </parameters>
</component>

I have looked at giving names to registered types but so far couldn’t find an example of how to use them from XML configuration.

In short I want to use XML configuration to specify which concrete logger implementation gets injection.

  • 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-04T04:12:45+00:00Added an answer on June 4, 2026 at 4:12 am

    XML configuration in Autofac is targeted more toward the 80% use case rather than being a full implementation of Autofac’s flexibility in XML form. Autofac instead recommends using its module mechanism for configuration. Modules, coupled with the XML configuration, can be a very powerful way to achieve what you’re looking to accomplish and still have that flexibility to switch between dependencies as needed.

    First, create an Autofac module that does the registration you want:

    public class EmailModule
    {
      protected override void Load(ContainerBuilder builder)
      {
        // Register a named logging service so we can locate
        // this specific one later.
        builder.RegisterType<LoggingService>()
               .Named<ILoggingService>("emailLogger");
    
        // Create a ResolvedParameter we can use to force resolution
        // of the constructor parameter to the named logger type.
        var loggingServiceParameter = new ResolvedParameter(
          (pi, ctx) => pi.Name == "loggingService",
          (pi, ctx) => ctx.ResolveNamed<ILoggingService>("emailLogger"));
    
        // Add the ResolvedParameter to the type registration so it
        // knows to use it when resolving.
        builder.RegisterType<EmailService>()
               .As<IEmailService>()
               .WithParameter(loggingServiceParameter);
      }
    }
    

    Notice it’s a little more complex of a registration because you’re requiring a very specific resolution.

    Now in XML configuration, register that module:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <section
          name="autofac"
          type="Autofac.Configuration.SectionHandler, Autofac.Configuration"/>
      </configSections>
      <autofac>
        <modules>
          <module type="EmailModule, MyAssembly" />
        </modules>
      </autofac>
    </configuration>
    

    When you want to switch configurations, register a different module rather than fiddling with specific component registries.

    Code disclaimer: I’m writing the syntax from memory and I’m not a compiler, so you may have to do a little tweaking… but the premise holds. Isolate the complexity in a module, then register your module.

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

Sidebar

Related Questions

Lets say I have one table called REVIEWS This table has Reviews that customers
Lets say I have an asp.net label that has the value: Label1.Text = Hello
Lets say we have a application which has a database - MySQL, SQL Server,
lets say I have tableA which has a col1 and tableB which has col2
Lets say I have a collection of applicants that can be accessed via /applicants
Lets say i have created a small game with XNA. Now i can change
Lets say I have a controller which provides search functions for a student: public
Lets say I have several web sites on my web server, all as applications
Lets say I have a single object of type Car which I want to
Lets say I have several sets of options in Javascript var color = [red,

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.