Search code examples
c#webassemblyblazor-webassembly

Can a component be added/registered after run time?


I would like to be able to do the following and am not sure if it is possible...

I would like to have a WASM Blazor application that can have components added after the application is compiled and running. For example, if I created a simple application that displays photos and give the user the ability to change the style by choosing a different component. Please ignore the fact that there may be better ways to "style", this is a simple example to illustrate my goal. Maybe these "style" components are listed and available for download but are NOT preloaded. I would like the user to be able to choose a different style and then, and only then, download the dll for the component from a remote repository and load that component into the running application so that it is available to render. I have looked into DynamicComponent and that shows some promise. But it seems as though most of the information I can find about this has the need to declare those types up front before compilation.

Does anyone know if what I am attempting is possible? Am I on the right track? Thanks!


Solution

  • You can hold off on loading assemblies until they are required using Lazy Loading, give this a read:

    https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-lazy-load-assemblies?view=aspnetcore-6.0