blazor-state
blazor-state copied to clipboard
Question! Any ideas ho to resolve state and action handlers in lazy loaded assemblies?
Microsoft.Extensions.DependencyInjection not supports lazy service registration, but in this case that would be useful. Do you have any ideas, how to solve this issue
hmm good question. One would have to register these after the library is lazy loaded.
@code {
private List<Assembly> lazyLoadedAssemblies = new();
private async Task OnNavigateAsync(NavigationContext args)
{
try
{
if (args.Path == "robot")
{
var assemblies = await AssemblyLoader.LoadAssembliesAsync(
new[] { "GrantImaharaRobotControls.dll" });
lazyLoadedAssemblies.AddRange(assemblies);
// here we would have to scan the assemblies and register appropriately.
}
}
catch (Exception ex)
{
Logger.LogError("Error: {Message}", ex.Message);
}
}
}
I will have to look into this to see a clean way to do it.
Ok, thank you. But i think, it is impossible without manual resolve new action handlers in lazy assemblies
Currently, it is impossible to use dependency injection with lazy loading. One way to do that, is to use IServciesProvider to the class constructor and fetch the registered classes. Then pass the instance of IServicesProvider by getting it inside the view using the dependency injection.