So I know I can use servicestack gap to embed resources into a dll…those resources must be loaded internally…so is there a method that is exposed or can be exposed as api so that I can read the contents of an embedded resource.
I’m trying to use servicestack razor as a fast email template engine, if I have the above I know I will be able to use a helper* to embed an inline css tag and I might not even need Premailer.NET to run on the after.
You can access embedded resources via the Virtual File System where you can read the contents of a file in a Service with:
var file = VirtualFileSources.GetFile("path/to/file.cshtml");
var razorHtml = file.ReadAllText();
Outside a Service you can use the HostContext.VirtualFileSources singleton.
If it helps here’s a generic Service that resolves and returns the contents of any File:
[Route("/files/{Path*}")]
public class GetFile
{
public string Path { get; set; }
}
public class FileServices : Service
{
public object Any(GetFile request)
{
var file = VirtualFileSources.GetFile(request.Path);
if (file == null)
throw HttpError.NotFound("File '{0}' does not exist".Fmt(request.Path));
return new HttpResult(file) {
ContentType = MimeTypes.GetMimeType(file.Extension)
};
}
}