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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:23:05+00:00 2026-06-04T10:23:05+00:00

I’m not sure if this is possible, but I though I’d ask the question

  • 0

I’m not sure if this is possible, but I though I’d ask the question anyway.

I have a scenario where I have a number of different tasks which send emails during processing.

The sending of emails is done via a custom class

public interface IEmailProvider
{
    void SendEmail(some params);
}
public class EmailProvider : IEmailProvider
{
    private readonly IEmailConfig _config;

    public EmailProvider(IEmailConfig config)
    {
        _emailConfig = emailConfig;
    }

    public void SendEmail(some params)
    {
        // send the email using the params
    }
}

I have some tasks which use the email provider, each providing their own implementation of IEmailConfig.

public class Task1 : ICommand
{
    public Task1(IEmailProvider emailProvider)
    {}
}

public class Task2 : ICommand
{
    public Task2(IEmailProvider emailProvider)
    {}
}

This is a basic example of my set up

public class TestInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        // Default email provider set up
        container.Register(Component.For<IEmailProvider>().ImplementedBy<EmailProvider>()
            .Named("DefaultEmailProvider")
            .LifeStyle.Transient);

        // Task 1 email config set up
        container.Register(Component.For<IEmailConfig>().ImplementedBy<Task1EmailConfig>()
            .Named("Task1EmailConfig"));

        // Task 2 email config set up
        container.Register(Component.For<IEmailConfig>().ImplementedBy<Task2EmailConfig>()
            .Named("Task2EmailConfig"));

        // Task 1 set up
        container.Register(Component.For<ICommand>().ImplementedBy<Task1>()
            .Named("Task1Command"));


        // Task 2 set up
        container.Register(Component.For<ICommand>().ImplementedBy<Task2>()
            .Named("Task2Command"));
    }
}

Is there a way I can make a decision, as each ICommand implementation is being resolved, as to which implementation of IEmailConfig to pass into the constructor of the EmailProvider class?

At the moment I register an EmailProvider instance for each task using the ServiceOverride functionality. This means that for each task that need to send emails, I have to almost duplicate the set up of the email provider and it’s required config. I end up with something list this…

Component.For<IEmailConfig>()
    .ImplementedBy<Task1EmailConfig>()
    .Named("Task1EmailConfig"));

Component.For<IEmaiProvider>()        
    .ImplementedBy<EmailProvider>)
    .Named("Task1EmailProvider")
    .DependsOn(ServiceOverride.ForKey("config").Eq("Task1Config"));

Component.For<ICommand>()
    .ImplementedBy<Task1>()
    .DependsOn(ServiceOverride.ForKey("emailProvider").Eq("Task1EmailProvider")));

This will all be duplicated for each task.

The IEmailProvider implementation is always the same, it’s only the IEmailConfig passed in that changes for each different task. I can’t help thinking there must be a neater solution to the one I’ve got so far.

  • 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-04T10:23:07+00:00Added an answer on June 4, 2026 at 10:23 am

    I think a couple of handler selectors would work for what you want. One for IEmailProvider and one for ICommand.

    The IEmailProvider one could check the name of the IEmailProvider being activated (like “Task1EmailProvider”) and strip off the “Provider” and add on “Config” — which would give you the key “Task1EmailConfig” which could be used to resolve the particular IEmailConfig object.

    Likewise, do the same thing for ICommand’s. It would rely on you naming your IEmailConfig’s consistently, but it would eliminate all of that hand-wiring you’re doing now.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and

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.