adoconnection / RazorEngineCore

.NET6 Razor Template Engine
MIT License
565 stars 84 forks source link

NET8 Component rendering to HTML for libraries outside Blazor! #139

Open A9G-Data-Droid opened 7 months ago

A9G-Data-Droid commented 7 months ago

It looks like NET8 brings us a new and improved way to render razor with their HtmlRenderer!

This could be a good opportunity to release a new major version of the RazorEngineCore with breaking changes and the new renderer. This would allow us to close any issues that are blocked due to breaking changes. Leave this version as it for legacy and make a new NET8 version!

https://andrewlock.net/exploring-the-dotnet-8-preview-rendering-blazor-components-to-a-string/

adoconnection commented 7 months ago

Thanks for pointing out, this is very interesting! BlazorEngineCore 😄

kingxi82 commented 7 months ago

This feature can be used to test the following Razor statements to see if they work correctly. Currently, RazorEngineCore does not support this C# 9 syntax

@{
    var ss = new { Qt="test"};
    string result = "";
    switch (ss)
    {
        case {Qt:"test"}:
            result = "show some text";
            break;
    }
    @:@result
}
A9G-Data-Droid commented 7 months ago

After looking deeper, I'm early. They are still arguing about the namespace and firming the architecture. I wouldn't experiment with this until they are done with things like this: https://github.com/dotnet/razor/issues/8400

They are moving the namespace used by this library. After the move to a final location, we can see how the new API fits into the CreateAndCompileToStream workflow.

kingxi82 commented 7 months ago

https://andrewlock.net/exploring-the-dotnet-8-preview-rendering-blazor-components-to-a-string/ I tested it according to the methods introduced in the article, and it worked well.

More about:

https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-components-outside-of-aspnetcore?view=aspnetcore-8.0