Search code examples
c#asp.net-mvc-3urlweb-applicationsservice-layer

How to generate URL in service layer of ASP.NET MVC 3 project


I am looking for a simple way (if it exists) to generate a URL in a service class for a specified controller and action in an ASP.NET MVC 3 web application. I want to do this in the service layer because of needing to encode this URL in a QR code.

This is simple in a View or in a controller because of the UrlHelper available through System.Web.Mvc so I could create the beginning of the URL in the controller action that uses my service class but I was hoping to do it at the point of QR code generation.

Thanks in advance.


Solution

  • A major reason for having distinct layers is separation of concerns. The service layer should not concern itself with request routing.

    I would pass the URL into the service layer and have the service layer return the generated QR code.