Skip to content

Allow lazy loading of code parts in a wasm apps #27811

@Stamo-Gochev

Description

@Stamo-Gochev

Extracted from #27331 (comment)

Is your feature request related to a problem? Please describe.

Currently, the lazy loading of assemblies in wasm does not allow initialization logic before the app has been launched., e.g. custom services cannot be injected - see #27331 (comment). Isolating the service injection code in a separate assembly is not always applicable due to backward compatibility reasons - clients of the product now need to use more than one assembly.

Describe the solution you'd like

As the service injection is done in the Startup.cs file and is not working, another approach for solving the problem might be to allow parts of the code to be marked as lazy loaded and manually initialized, thus allowing services to be initialized on the page that uses lazy loading. For example, an attribute can be used to specify this - LazyLoaded. Thus the service:

builder.Services.AddSingleton<SomeDependencyService>();

can be initialized on the lazy loaded page like:

@code {
        [LazyLoaded]
        // NOTE: Currently this throws an error
        public SomeDependencyService Service{ get; set; } = new SomeDependencyService();
}

The attribute approach might not be optimal, thus any other method for allowing this is welcome.

Additional context

#27331 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-fewThis issue impacts only small number of customersarea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-lazy-loadingIssues related to adding support for lazy-loading in Blazorfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssemblyseverity-majorThis label is used by an internal tool

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions