Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy load Blazor modules/assemblies #5543

Open
hikalkan opened this issue Sep 21, 2020 · 7 comments
Open

Lazy load Blazor modules/assemblies #5543

hikalkan opened this issue Sep 21, 2020 · 7 comments

Comments

@hikalkan
Copy link
Member

We should work on a general system to lazy load module assemblies.
Need to upgrade to .NET 5: https://docs.microsoft.com/en-us/aspnet/core/blazor/webassembly-lazy-load-assemblies

@ghd258
Copy link

ghd258 commented Dec 13, 2020

Why delay

@hikalkan
Copy link
Member Author

ABP modules require to be initialized on application startup. They registers services to dependency injection for example. I didn't see in Microsoft's document how we register services to Dependency Injection (DI) for lazy loaded assemblies. As I know, it is not possible to register services to DI after the application has started.
So, I wanted to postpone this to investigate more in the next milestone. If you know and you can help, it is appreciated.

@hikalkan hikalkan modified the milestones: 4.3-preview, 4.2-final Dec 17, 2020
@leonkosak
Copy link
Contributor

This should greatly improve this issue, right?
#6269 (comment)

@hikalkan hikalkan modified the milestones: 4.3-preview, 4.4-preview Mar 2, 2021
@hikalkan
Copy link
Member Author

hikalkan commented Mar 2, 2021

This should greatly improve this issue, right?

I don't think so, to be honest. In any way, this milestone we are more focused on server side blazor (which will improve performance when you use), so we will try to work on it in the next milestones.

@muratyuceer
Copy link
Contributor

muratyuceer commented Apr 30, 2021

also we think about api-definition result size, my application growing but already 2mb

image

@hikalkan hikalkan removed the effort-8 label May 18, 2021
@hikalkan hikalkan assigned stsrki and unassigned stsrki May 18, 2021
@stsrki
Copy link
Contributor

stsrki commented May 19, 2021

As @hikalkan already mentioned. The main issue with lazy load is that we do a lot of things with DI. So no matter what we do, it will always load all of the modules at once.

Since lazy-load is not an option I think the best way to do this would be to implement prerendering. But the current .Net5 prerendering has its own limitations. For example, when the app is loaded on the client it still needs to get the app state from the server and to re-render a second time. And when it does, it will do (ugly) a small flicker.

There is a better way, but it is only available in new .Net6 so I think it is best to wait until it is released.

https://jonhilton.net/blazor-prerendering-net6/

@hikalkan hikalkan modified the milestones: 4.4-preview, 5.0-preview Jun 9, 2021
@hikalkan hikalkan modified the milestones: 5.0-preview, backlog Sep 16, 2021
@abpframework abpframework deleted a comment from ghd258 Nov 25, 2021
@mostafayakout
Copy link

mostafayakout commented Mar 3, 2022

we can do the following steps as a temporal solution :

1- add route component in the Blazor webAssembly client project to be the same as the one provided by default from ABP to use all features included App.razor
2- make small changes on the component to be like that

@using Microsoft.Extensions.Options
@using Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic
@using Volo.Abp.AspNetCore.Components.Web.Theming.Routing
@using System.Reflection
@inject LazyAssemblyLoader lazyLoader
@inject IOptions<AbpRouterOptions> RouterOptions
<CascadingAuthenticationState>
    <Router AppAssembly="RouterOptions.Value.AppAssembly" OnNavigateAsync="OnNavigateAsync"
            AdditionalAssemblies="lazyLoadedAssemblies">
        <Found Context="routeData">
            <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
                <NotAuthorized>
                    @if (!context.User.Identity.IsAuthenticated)
                    {
                        <RedirectToLogin />
                    }
                    else
                    {
                        <p>You are not authorized to access this resource.</p>
                    }
                </NotAuthorized>
            </AuthorizeRouteView>
        </Found>
        <NotFound>
            <LayoutView Layout="@typeof(MainLayout)">
                <p>Sorry, there's nothing at this address.</p>
            </LayoutView>
        </NotFound>
    </Router>
</CascadingAuthenticationState>
@code {
    private List<Assembly> lazyLoadedAssemblies = new List<Assembly>();
    protected override Task OnInitializedAsync()
    {
        lazyLoadedAssemblies = RouterOptions.Value.AdditionalAssemblies;
        return base.OnInitializedAsync();
    }
    private async Task OnNavigateAsync(NavigationContext args)
    {
        if (args.Path.EndsWith("counter"))
        {
            var assemblies = await lazyLoader.LoadAssembliesAsync(
                new List<string> { "MathNet.Numerics.dll" });
            lazyLoadedAssemblies.AddRange(assemblies);
        }
    }
}

3- in this case we can make use of register additional assemblies using Abp configure service feature and also control lazy loading easily

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants