对于 .NET 控制台应用程序来说,什么是好的模板引擎?

发布于 2024-10-03 04:59:33 字数 821 浏览 1 评论 0原文

我们正在寻找一种快速、灵活的方法来从 .NET 控制台应用程序生成模板化内容(在本例中为文本和 HTML 格式的个性化电子邮件)。

我们没有 VirtualPathProvider,也没有有效的 HttpContext.Current,从我们最初的实验来看,这意味着使用 WebForms 视图引擎将非常非常困难,并且任何其他 .NET Web 视图引擎(Spark、Razor)都无法使用。需要大量的管道来让他们认为他们正在网络应用程序中运行。

我想要做类似的事情:

var customerTemplateData = GetTemplateDate(customer);
var htmlBody = templateEngine.Render("template.html", customerTemplateData);
var textBody = templateEngine.Render("template.txt", customerTemplateDate);
SendMail("[email protected]", customer.Email, "Hey there!", htmlBody, textBody);

并且我想要使用复杂的嵌套数据、列表内的大量列表来执行此操作,每分钟最多 1,000 次。

任何有关专用模板引擎或在独立上下文中运行 Web 视图引擎的方法的建议都将受到高度赞赏:)

谢谢,

Dylan

We're looking for a fast, flexible way of generating templated content (in this case personalized e-mails in text and HTML format) from a .NET console application.

We have no VirtualPathProvider and no valid HttpContext.Current, which, from our initial experiments, means it's going to be very, very hard to use the WebForms view engine, and any of the other .NET web view engines (Spark, Razor) are going to need extensive plumbing to make them think they're running in a web app.

I want to do something like:

var customerTemplateData = GetTemplateDate(customer);
var htmlBody = templateEngine.Render("template.html", customerTemplateData);
var textBody = templateEngine.Render("template.txt", customerTemplateDate);
SendMail("[email protected]", customer.Email, "Hey there!", htmlBody, textBody);

and I want to do it with complex nested data, lots of lists inside lists, up to 1,000 times a minute.

Any recommendations for dedicated template engines or for ways to run the Web view engines in a standalone context would be most appreciated :)

Thanks,

Dylan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半﹌身腐败 2024-10-10 04:59:33

如果您正在寻找有关如何使用 Spark 实现此目标的一些指导,可以使用功能齐全的 电子邮件和文本模板示例可在 Spark 源代码中找到。

应该注意的是,该示例实际上不依赖于 HttpContext 或任何其他 Web 基础设施。它是完全独立的,可以像控制台应用程序一样轻松运行。

希望这有帮助,
祝一切顺利,

If you're looking for some guidance on how you'd achieve this with Spark, there is a fully functional Email and Text Templating Sample available here in the Spark source code.

It should be noted that there is actually no dependency that this sample has on HttpContext or any other web infrastructure for that matter. It's completely independant and could just as easily run as a console application.

Hope this helps,
All the best,
Rob

绿萝 2024-10-10 04:59:33

从命令行创建模板化内容的方法有很多,NVelocity 就是一个例子,而且最近我们还在 CodePlex 上发布了 Razor 解析器的包装器 ( http://razorengine.codeplex.com/ )我认为值得一看。

There are quite a few ways of creating templated content from the command line, NVelocity is an example, but also recently we're released our wrapper of the Razor parser on CodePlex ( http://razorengine.codeplex.com/ ) which I think is worth a look into.

浅暮の光 2024-10-10 04:59:33

还有一个,
StringTemplate 模板引擎

不过,我很关注RezorTemplateEngine!

Yet another,
StringTemplate Template Engine.

However, I am attention to RezorTemplateEngine!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文