Share via

blazor component runtime nested

shahab biabani 41 Reputation points
2021-07-28T15:05:18.143+00:00

Hi

My goal is to put the components together in runtime, even nested.(like page designer sharepoint)

There are two incomplete ways to do this.

1- Using DynamicComponent 2- Using RenderTreeBuilder

Both of these solutions do not work in practice when used in nested(RenderFragment) components.

And a complete way to generate files in run time.(generate .razor)

But the problem with this method is that it is compile in runtime.

(in asp.net web-form and asp.net core/mvc you can use AddRazorRuntimeCompilation method But not work in Blazor)

What is your solution to this challenge ?

Developer technologies | .NET | Blazor
0 comments No comments

Answer accepted by question author

Bruce (SqlWork.com) 84,086 Reputation points
2021-07-29T01:27:27.317+00:00

You don’t say if this is server or WASM blazor, but you run into the same issue SharePoint had.

In webforms all asps pages needed to be compiled via the aspnet compiler before being loaded. Then the compiled dll is loaded into memory via an appdomain. You cannot unload a dll only an app domain. To allow scaling SharePoint used a no compile feature of webforms, but this did restrict what code a page could do.

Blazor or razor components require a compile. The razor template is converted to it code (just webforms). Unlike webforms, there is no runtime compiler, and blazor WASM does not have any compiler. Core has added support for unloading assemblies loaded via a context, but it require the client code to release all theads using it.

Assuming unload is not an issue, you need to create a razor compiler service. You code would call this service to compile the dll, and use blazor’s lazy loading support to use the component.

This will be a challenging project. The requirements do not match up well with the features of a strongly typed compiled toolset.

Compare to coding this react next.js or gatsby, both node frameworks.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.