我如何将此代码移到我的 asp.net-mvc 项目之外
我的 asp.net-mvc 项目中有以下代码:
private string GenerateEmail(RequestContext requestContext)
{
var u = new UrlHelper(requestContext);
string url = u.AbsoluteAction("Detail", "Application", new { id = app.Id });
}
我使用 UrlHelper 因为我希望将完整的 url 放入电子邮件中(而不是相对 url),并且它在我的 mvc 项目中效果很好,
我现在希望能够从另一个解决方案(不是基于网络的)生成这些电子邮件,所以我尝试在 mvc 项目之外重构所有电子邮件代码,但这是我无法删除的一行(因为 UrlHelper 依赖于System.Web.MVC)
在不依赖 System.Web.MVC 的“通用”C# 项目中分解此代码的最佳方法是什么?
I have the following code inside my asp.net-mvc project:
private string GenerateEmail(RequestContext requestContext)
{
var u = new UrlHelper(requestContext);
string url = u.AbsoluteAction("Detail", "Application", new { id = app.Id });
}
I use the UrlHelper because I want the full url to be put in the emails (not a relative url) and it works great in my mvc project
I now want to be able generate these emails from another solution (which is not web based) so i tried refactoring all of my email code outside of the mvc project but this is the one line I can't remove (since UrlHelper depends on System.Web.MVC)
what is the best way to factor out this code in a "generic" C# project that doesn't have a dependency on System.Web.MVC ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以在 ViewController 中提取 URL,然后将 URL 作为字符串传递给电子邮件发送器类。
因此,如果您使用如下例所示的方法创建电子邮件发送器类,则电子邮件发送器将独立于 MVC 框架:
It´s OK to extract the URL in the ViewController and then pass the URL as a string to the emailer class.
So if you create the emailer class with a method like the example below, the emailer will be independent of the MVC framework: