Should dependencies be stored in private fields or properties with private setters and public recipients? This applies to the DI constructor.
To be clear, in the example of properties, I did not expect that they would be added to the accompanying interface, if that makes no sense - that is, they will be visible only in the implementation type:
interface IFoo {
void DoSomething();
}
class Foo : IFoo {
private readonly IService dependency;
public Foo(IService dependency) {
this.dependency = dependency;
}
}
class Bar : IFoo {
public Foo(IService dependency) {
this.Dependency = dependency;
}
public IService Dependency { get; private set; }
}
source
share