Can someone explain what are the differences, pros/cons between
RazorEngine
RazorTemplates
RazorMachine
I need to pick one for email generation. The requirements are quite usual: fast, ease-of-use. It seems like all of them has all features I need but as I'm Razor newbie it's not quite clear to me which one is better.
Thanks.
I have tried all 3 libraries myself and found several differences.
dynamic
types. Can use precompiled templates.As to me, I have chosen RazorEngine. Also here is the code how to use these libraries:
RazorEngine
string html = Razor.Parse(templateContent, model, templatePath);
RazorTemplates
if (!_templatesCache.ContainsKey(templatePath))
{
var compiledTemplate = Template.Compile(templateContent);
_templatesCache.Add(templatePath, compiledTemplate);
}
string html = _templatesCache[templatePath].Render(model);
RazorMachine
private readonly Lazy<RazorMachine> _lazyRazorMachine =
new Lazy<RazorMachine>(() => new RazorMachine());
//...
var rm = _lazyRazorMachine.Value;
string html = rm.ExecuteContent(templateContent, model, null, true).Result;
And some performance tests, tested each library 2 times on the same template, all of them have a similar performance without a big difference:
RazorEngine - 1731 ms, 0.1 ms
RazorTemplates - 1753 ms, 0.1 ms
RazorMachine - 1608 ms, 0.1 ms
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With