构造函数注入(C)
public class Foo
{
private readonly IBar _iBar;
public Foo(IBar iBar)
{
_iBar = iBar;
}
public void DoStuff()
{
_bar.DoSomething();
}
}
public interface IBar
{
void DoSomething();
}
public class Foo
{
private readonly IBar _iBar;
public Foo(IBar iBar)
{
_iBar = iBar;
}
public void DoStuff()
{
_bar.DoSomething();
}
}
public interface IBar
{
void DoSomething();
}