有没有办法在kernel.Bind<>().ToMethod()
内引用父的构造函数参数(实际上是IProvider
)?
我的情况如下:
public class Bar{
public Bar(ILogger logger) {}
}
public class Foo{
public Foo(ILogger logger, Bar bar){}
}
让我说我有一些记录器:
public class TopLevelLogger{
}
public class ChildLogger{
public ChildLogger(ILogger parent){}
}
当我设置我的绑定时,我需要获得对父类的记录器的引用:
kernel = new StandardKernel();
kernel.Bind<ILogger>.ToMethod(ctx =>
{
if (null == ctx.Request.ParentRequest.ParentRequest)
// at top level (ie Foo)
return new TopLevelLogger();
// I know I've already created a TopLevelLogger, how do I get access to it?
var parentLogger = ???????
return new ChildLogger(parentLogger);
});