Using basic RazorEngine to render Templates

The following topics demonstrate how to use the base RazorEngine and RazorEngine classes to render templates. These core classes provide the base engine for loading, parsing, compiling and rendering of templates.

These base implementations make no provisions on caching assemblies or code however, so everytime you run a template it will be regenerated and recompiled and reloaded which is reasonably fast but wastes resources quickly. You can compile templates manually and hang on to the Engine reference and a compiled template ID to reexecute an already compiled template.

Optionally you can use the RazorHostFactory class to create a host in a remote AppDomain that can be unloaded to allow some control over the resource usage and the ability to unload assemblies.

To provide for assembly caching for string and folder based template hosting, the Host wrappers (RazorFolderHost and RazorStringHost) provide caching of assemblies that reduce resource use and improve repeat execution performance.


© West Wind Technologies, 2018 • Updated: 05/29/17
Comment or report problem with topic