StackOverflow 文档 Design patterns 教程 依赖注入 setter 注入(C) setter 注入(C) Created: November-22, 2018 public class Foo { private IBar _iBar; public IBar iBar { set { _iBar = value; } } public void DoStuff() { _iBar.DoSomething(); } } public interface IBar { void DoSomething(); } 构造函数注入(C)依赖注入