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

Question! Any ideas ho to resolve state and action handlers in lazy loaded assemblies? #260

Open
megafetis opened this issue Aug 8, 2021 · 3 comments

Comments

@megafetis
Copy link
Contributor

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

@StevenTCramer
Copy link
Collaborator

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.

@megafetis
Copy link
Contributor Author

Ok, thank you. But i think, it is impossible without manual resolve new action handlers in lazy assemblies

@theumairtahir
Copy link

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.

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

No branches or pull requests

3 participants