0

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 ?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
leora
  • 188,729
  • 360
  • 878
  • 1,366

1 Answers1

2

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)
{
}
Espen Burud
  • 1,871
  • 10
  • 9