Search code examples
asp.netasp.net-mvcdependency-injectionasp.net-core-mvccommon.logging

ASP.NET Core Dependency injection for Common.Logging


I want to be able to configure ASP.NET's dependency injection framework to be able to resolve me an instance of Common.Logging's ILog interface. Creating an instance of ILog is done via the Common.Logging's static LogManager.GetLogger methods which require a type as a parameter.

This means that when resolving an instance of ILog I need to know the target type that the DI engine is trying to inject into. In the past I've used autofac modules to solve this problem which other have asked about here, but it would nice to be able to do this purely with ASP.NET's built in Ioc.

I can see that there is the ability to resolve an instance by creating a method that takes an IServiceProvider, but there is no context of the type being injected into that I can see.

Does anyone know how a service can be resolved at runtime with knowledge of the type its being injected into?


Solution

  • I posted the same question in the ASPNET dependencyinjection repo issue register and apparently its not possible.