简体   繁体   中英

dynamic lazy loading in blazor

In a Blazor wasm project I would like to dynamically load a second project without knowing the project at compile time (.Net5). Therefore the normal 'lazy loading' does not work for me. Are there libraries for such purposes? Or an example solution

I am also looking for this capability. The static compile time referance in .net 6 is not great.

Have a look at oqtane they were doing some work in lazy loading at runtime back in .net 3.1, unfortunatly it seems that they went more into a nuget direction instead of just dll's https://docs.oqtane.org/index.html https://github.com/oqtane/oqtane.framework/discussions/1076

A little late here but in.NET 6 you can do it, I did a Manager where you can look at

https://github.com/elgransan/BlazorPluginComponents

Some example code

        var componentPackage = "RazorClassLibrary2";
        var component = "Component2";
        var stream = await Http.GetStreamAsync($"{MyNavigationManager.BaseUri}/{componentPackage}/{componentPackage}.dll");
        var assembly = AssemblyLoadContext.Default.LoadFromStream(stream);
        componentType = assembly.GetType(componentPackage + "." + component);
        await DOMinterop.IncludeLink(componentPackage, $"/{componentPackage}/{componentPackage}.styles.css");

Where the files are in the server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM