我如何将此代码移到我的 asp.net-mvc 项目之外

发布于 2024-12-23 04:39:35 字数 485 浏览 4 评论 0原文

我的 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 技术交流群。

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

发布评论

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

评论(1

红衣飘飘貌似仙 2024-12-30 04:39:35

可以在 ViewController 中提取 URL,然后将 URL 作为字符串传递给电子邮件发送器类。

因此,如果您使用如下例所示的方法创建电子邮件发送器类,则电子邮件发送器将独立于 MVC 框架:

public string GenerateEmailBodyFromUrl(String url)
{
}

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:

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