Search code examples
c#logginginversion-of-controlautofacconstructor-injection

Specify dynamic method for interface resolution on type resolving in Autofac


Many of my classes are accepting some ILogger interface.

This interface is implemented by a class that can accept the context it should log.

So in practice when passing ILogger, what I want to pass is new Logger(nameof(<type>), depending on the <type> we are currently resolving.

Can this be done in some sort in Autofac without specifically stating the contructor parameters for each type? since this is always the behavior I want to achieve when Autofac resolves ILogger injection parameter.


Solution

  • Found a formal example in Autofac documentation:

    http://docs.autofac.org/en/latest/examples/log4net.html