简体   繁体   English

blazor 中的动态延迟加载

[英]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).在 Blazor wasm 项目中,我想动态加载第二个项目,而不知道编译时的项目(.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. .net 6 中的 static 编译时参考不是很好。

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看看 oqtane,他们在 .net 3.1 的运行时在延迟加载方面做了一些工作,不幸的是,他们似乎更多地进入了 nuget 方向,而不仅仅是 dll 的https: //docs.oqtane.org/index.html 852075683: //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这里有点晚了,但在 .NET 6 中你可以做到,我做了一个管理器,你可以在其中查看

https://github.com/elgransan/BlazorPluginComponents 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文件在服务器中的位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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