Expose activation context when using factory methods

IoC containers like Ninject expose the “activation context” in factory methods that allows the creator to understand the context in which the instance is being created. My specific pratical need is the following:

container.AddTransient<ILog>(context => LogManager.GetLogger(context.GetScope()));

This way I could inject an instance of ILog that has the type parameter as the type in which he is getting injected into.

Is it possible to have this kind of information inside factory methods?

No, that information doesn’t exist in the impl or any of the APIs and would prohibitive to add, tightly coupled and inefficient to create per dependency.

The Logging API is designed to support static initialization which ensures there’s only a single instance created per type.

If you want to the logging injected with the type you would need to inject the factory and create the instance from that, which you can do lazily with something like:

ILog log;
public ILogFactory LogFactory { get; set; }
public ILog Log => log ?? (log = LogFactory.GetLogger(GetType()));

Which can also be added to a base class if preferred.