Dependency injection through constructors or property setters?

Well, it depends :-).

If the class cannot do its job without the dependency, then add it to the constructor. The class needs the new dependency, so you want your change to break things. Also, creating a class that is not fully initialized (“two-step construction”) is an anti-pattern (IMHO).

If the class can work without the dependency, a setter is fine.

Leave a Comment