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

  • Home
  • SEARCH
  • 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 943981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:31:12+00:00 2026-05-15T22:31:12+00:00

I am working on a component for merging arbitrary tokens with text in order

  • 0

I am working on a component for merging arbitrary tokens with text in order to generate e-mails. I am going to be using nvelocity for the merging process, so I have defined the following interface:

public interface ITemplateEngine
{
    string Merge(string template, IDictionary<string, object> data);
}

Now, in my scenario, the implementing class returns a string containing xml (subject, body nodes). Next, I need a intermediate class used to return a mail item. Here is the class.

    public class MailMessageBuilder : IMailMessageBuilder
{
    private readonly ITemplateEngine engine;

    public MailMessageBuilder(ITemplateEngine engine)
    {
        this.engine = engine;
    }

    public MailMessage Build(string name, IDictionary<string, object> tokens)
    {
        var doc = new XmlDocument();
        doc.LoadXml(engine.Merge(name, tokens));

        var msg = new MailMessage();
        var node = doc.DocumentElement.SelectSingleNode("Body");

        msg.Body = node.InnerText;
        msg.IsBodyHtml = bool.Parse(node.Attributes.GetNamedItem("isHtml").Value);
        msg.Subject = doc.DocumentElement.SelectSingleNode("Subject").InnerText;

        return msg;
    }
}

Now to my real question, do you think my mail message builder class is doing more than he should since he is pulling out the values from the xml? If so, any other design ideas?

Thanks!

  • 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-15T22:31:12+00:00Added an answer on May 15, 2026 at 10:31 pm

    Now to my real question, do you think
    my mail message builder class is doing
    more than he should since he is
    pulling out the values from the xml?
    If so, any other design ideas?

    I think its fine that he’s pulling out values from the XML and putting them in the MailMessage class since the only way to abstract that would be to extract the values into something else that you then mapped over to MailMessage. In other words, that part is doing only one thing, mapping the XML into your MailMessage.

    The place where I think you might be violating SRP is in doing the Engine.Merge call inside there, that seems like it should be done externally to the function and the string result passed in instead of the name and Dictionary. (I’d also change that MailMessageBuilder so that the parameter name does not match exactly the private member name, which forces you to use “this”, but that’s a minor point.)

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

Sidebar

Related Questions

I am working on one component where I need to scale and rotate image.
I am started working on resume retrieval(document) component based on lucene.net engine. It works
I'm working on an Android app with a Java component and a C++ component
I'm working on a Firefox NPAPI plugin + XPCOM component. I've run into a
I've been working on a fork of critical component of our source tree, and
I built a Joomla 1.5 component, non-MVC, and it's working fine, so I'd rather
I am new to Blackberry. Present I am working on 4.7 Blackberry component pack.Now
I'm new to component development in Delphi, therefore want to know, is it possible
I'm trying to figure out how to programmatically apply a theme at runtime in
Our project is a content management system supporting several dozen of our websites. 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.