假设我有这段代码(一般而言),假设我需要在 C 类中使用 ILogger,而在 A 类和 B 类中不需要它
public class A
{
var classB = new B();
}
public class B
{
var classC = new C();
}
public class C
{
//Here I want to use the Ilogger service
}
Run Code Online (Sandbox Code Playgroud)
但沿着这整条链条传递构造函数似乎不合理,而且随着使用的服务的增加,构造函数只会增长。那么如何正确调用C类的服务呢?谢谢