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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:26:29+00:00 2026-06-17T23:26:29+00:00

Is it possible to configure multiple implementations of the same interface with the autofac

  • 0

Is it possible to configure multiple implementations of the same interface with the autofac xml configuration?

What i’m trying to accomplish is a windows service which executes multiple jobs. I have 2 jobs which are sending messages from a queue by sms or email. Every job is a different assembly. They both depend on IQueuedMessageProvider. One job needs the email implementation the other one the sms implementation.The constructor for both jobs look like this (simplified for question):

 public SendSmsJob(IQueuedMessageProvider queuedMessageProvider)
    {
        _queuedMessageProvider= queuedMessageProvider;
    }
 public SendEmailJob(IQueuedMessageProvider queuedMessageProvider)
    {
        _queuedMessageProvider= queuedMessageProvider;
    }

In the app.config I registered the implementations like

<component type="MyApp.Plugin.Sms.Verizon.VerizonSmsService, MyApp.Plugin.Sms.Verizon" service="MyApp.Model.Messages.QueuedMessages.Providers.IQueuedMessageProvider, MyApp.Model" />
<component type="MyApp.Plugin.Email.Smtp.EmailService, MyApp.Plugin.Email" service="MyApp.Model.Messages.QueuedMessages.Providers.IQueuedMessageProvider, MyApp.Model" />

How can I make sure the job gets the right implementation of de IQueuedMessageProvider? I have read about solving these kind of problems with names and keys https://code.google.com/p/autofac/wiki/TypedNamedAndKeyedServices.

Another option is register all implementations and make IQueuedMessageProvider an IEnumerable and take the right implementation in the constructor. But I prefer to solve it in the configuration it self. Is it even possible or do you have any better suggestions about solving this?

  • 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-17T23:26:30+00:00Added an answer on June 17, 2026 at 11:26 pm

    Autofac’s XML configuration, at the time of this writing, has the ability to specify a name/key for a service (like your message providers) but can’t specify that a given type on a different service’s constructor (the “job” classes) get associated with a particular name.

    You have effectively three options.

    Option 1: Redesign your interfaces

    The point of having an interface (or an abstract/base class) is that you can use implementations interchangeably. (See: Liskov substitution principle.) If your design is such that you can’t do that (which is how it appears) then it would be good to reinvestigate that design. You might need different interfaces for different tasks.

    Looking at the small snippet provided, I might think about having different interfaces for each method of transport (ISmsProvider, IEmailProvider) so the processor “job” classes can key appropriately by type.

    Option 2: Use Autofac modules

    If you have different “known configurations” (e.g., one for development, one for production) then you could create different Autofac modules for each configuration. You can be much more flexible in a module than you can in XML configuration and it would allow you to do the fancy wire-up-by-named-instance stuff you need to do.

    You can use XML configuration to register modules just like you can for types, so rather than switching the XML config type registrations based on your different requirements, change the XML config to register a different module.

    Option 3: Implement your own XML config parser

    As of Autofac 3.0, the configuration mechanism has a way to write your own mechanism that parses and registers XML configuration. The documentation on the site isn’t updated quite yet, and there’s no “cookbook” or sample, so you’ll have to do some spelunking in the source, but technically it’s possible. I’d probably look at one of the first two options before diving into this one.

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

Sidebar

Related Questions

Is it possible to configure multiple database servers (all hosting the same database) to
Is it possible to configure nginx to query a service (not DNS) to determine
In Windows Forms, is it possible to configure a drop-down combobox control so that
I want to be able to develop a windows service which is capable of
Is it possible to configure the Windows Workflow SqlWorkflowPersistanceService to use different SQL Server
Possible Duplicate: Configure MPI hostsfile to use multiple user identities Does anyone know it
Is it possible to configure a Procfile to support multiple web endpoints (either by
I would like to know if it's possible to call multiple @configure calls or
Possible Duplicate: How do I configure multiple databases work in Play 2.0? Basically, I
The question: Is it possible to configure multiple SMTP servers or update the SMTP

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.