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!