Description
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.