Resolve type based on target type being injected into
davevans opened this issue · 2 comments
davevans commented
I'm trying to move a codebase from using Autofac to vanilla ASPNET dependency injection. One issue I have is how to configure the registration of a type where the resolving the type at runtime requires knowledge of the type being resolved for.
The same question has been asked and solved for Autofac using Autofac modules which give you hooks into the type being injected into.
So how can I add a transient registration and know the type that is requesting resolution?
services.AddTransient<ILog>(sp => LogManager.GetLogger(typeof(??)));
davidfowl commented
It's not possible to do this with the built in DI container.
davevans commented
Copy that. Thanks @davidfowl.