(DI) . , DI - , . DI , . , DI, DI Service .
, , , ? , : - (-). , . .
DI DI. DI, .
, DI, :
public class Foo : IFoo
{
private readonly IBar bar;
public Foo(IBar bar)
{
if (bar == null)
{
throw new ArgumentNullException("bar");
}
this.bar = bar;
}
public IBaz Baz(ISnafu snafu)
{
return this.bar.Snafize(snafu).ToBaz();
}
}
IBaz , Foo. , , , Foo IBar - IFoo:
public class MyClass : ISomeInterface
{
private readonly IFoo foo;
public MyClass(IFoo foo)
{
if (foo == null)
{
throw new ArgumentNullException("foo");
}
this.foo = foo;
}
}
, DI. .