RazorLight v2.0 Release Notes

Release Date: 2017-09-23 // about 4 years ago
  • What is new?

    String rendering is back!

    ๐ŸŽ We added rendering of the strings back! And now they are cached, so you will not be affected by bad performance.

    Note: if you store your templates in database - it is recommended approach to define custom RazorLightProject that fetches templates from database and create RazorLightEngine passing your implementation to it. This way, engine will your RazorLightProject to resolve layouts. String rendering is just another option for some exclusive use cases when you have microservice structure and pass templates between nodes, so you might not need it at all.

    Here is an example of RazorLightProject that uses EntityFramework to get templates from database- https://github.com/toddams/RazorLight/blob/dev-2.0/samples/RazorLight.Samples/Program.cs

    string templateKey = "key";string result = await engine.CompileRenderAsync(templateKey , "Hello @Model.Name", new { Name = "Johny" });//Returns true, so next time you render template with this key - it will not be compiled, but taken from cacheengine.TemplateCache.Contains(templateKey); 
    

    โž• Additional metadata references

    ๐Ÿ“‡ When RazorLight compiles your template - it loads all the assemblies from your entry assembly and creates MetadataReference from it. This is a default strategy and it works in 99% of the time. But sometimes compilation crashes with an exception message like "Can not find assembly My.Super.Assembly2000". In order to solve this problem you can pass additional metadata references to RazorLight.

    var options = new RazorLightOptions();var metadataReference = MetadataReference.CreateFromFile("path-to-your-assembly")options.AdditionalMetadataReferences.Add(metadataReference );var project = new FileSystemRazorProject("path-to-your-views");var engine = new EngineFactory().Create(project, options);
    

Previous changes from v2.0-alpha2

  • What is new?

    • โž• Added support for includes via @{ await IncludeAsync("key", model); }
    • Disable encoding

    As always, you can avoid encoding using @Raw() function

    @Raw(Model.Data)
    

    Or disable encoding for entire document

    @{ DisableEncoding = true; }
    

    ๐Ÿ’ฅ Breaking change

    • GetTemplateAsync is now called CompileTemplateAsync