在我完全理解依赖注入容器的过程中,我想到了这个场景:
public interface I{
String exampleAction();
}
public class ConcreteA implements I{
@Override
String exampleAction(){return "A";}
}
public class ConcreteB implements I{
@Override
String exampleAction(){return "B";}
}
public class Start{
public static void main(){
IoC.register<ConcreteA>().as<I>();
}
new ActualQuestion(IoC.Resolve<I>(),IoC.Resolve<I>());
}
public class ActualQuestion{
private I first;
private I second;
public ActualQuestion(I needA,I needB){
first=needA;
second=needB;
}
}
这种情况在良好的代码中是否永远不会发生?我觉得它会在某个时候