I have some service which does some file processing. It may need to map to arbitrary paths, and I’m tried to keep it as decoupled from a controller as possible. Normally, I could just do something like:
var path = Server.MapPath("~/Content/Images/");
var imageFile = Path.Combine(path, filename);
But if I’m trying to do this outside of a controller, I don’t have access to Server. Is there any simple and clean way I could map to paths without relying on Server?
AppDomain.CurrentDomain.DynamicDirectorycan give you the directory the application domain is executed from, which is independent of any controllers and can be used through your whole application.