AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Lazy Loading and Dependency Injection in Blazor

Open ympaul opened this issue 5 years ago • 2 comments

Hi,

I read the article and tried. I notice that if I do LazyLoading, I cannot do dependency injection for the lazyLoaded assemblies due to container being immutable.

Is there any workaround regarding this ? without having to create a factory class and manually creating your class for dependency.

Regards, Paul


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

ympaul avatar Oct 19 '21 03:10 ympaul

Hello @ympaul ...

Open this for the product unit at ...

https://github.com/dotnet/aspnetcore/issues

Please add a cc: @guardrex to your opening comment there. I'll re-open this if they provide guidance that we need to add to the topic for this.

guardrex avatar Oct 19 '21 11:10 guardrex

Just FYI, the primary way I've solved this issue is as you nodded to and basically use the Service Locator Pattern with a factory class to dynamically resolve the dependencies for the LL assembly at runtime. As you mentioned the DI container is immutable once loaded, and can't resolve a dependency that does not yet exist.

Fear not though, while it's not seamless it's also not too difficult to setup either.

AllenConway avatar Nov 04 '23 00:11 AllenConway