Saturday, 31 August 2013

Is this dependency injection?

Is this dependency injection?

A simple question that is perhaps a bit silly. Is this dependency
injection? I do not mean a DI container.
Foo depends on an instance of Bar. Foo gets an instance of Bar passed by
constructor and does not care even for the initialization.
public class Foo
{
public Foo(IBar bar)
{
DoSomething(bar);
}
private void DoSomething(IBar bar)
{
// ...
}
}
public class Bar : IBar
{
// ...
}
Is passing an instance of Bar to the constructor a dependency injection?
Especially constructor injection.

No comments:

Post a Comment