在 Autofac 中指定类型解析接口解析的动态方法

Specify dynamic method for interface resolution on type resolving in Autofac

我的许多 class 正在接受一些 ILogger 界面。

此接口由 class 实现,可以接受它应该记录的上下文。

所以实际上在传递ILogger的时候,我想传递的是new Logger(nameof(<type>),这取决于我们目前正在解析的<type>

这可以在 Autofac 中以某种方式完成,而无需具体说明每种类型的构造函数参数吗?因为当 Autofac 解析 ILogger 注入参数时,这始终是我想要实现的行为。

Autofac 文档中找到正式示例:

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