Thursday, June 04, 2015

Too many parameters in my constructors.

If I have too many parameters in my constructor, that means my class is doing too many things.

Quotes from this article: http://blog.ploeh.dk/2010/02/02/RefactoringtoAggregateServices/

"Surely, five constructor parameters are too many."

"Constructor Injection makes SRP violations glaringly obvious."

If you think that I should use a dependency injection framework, I disagree.

I agree with this article: http://blog.schauderhaft.de/2012/01/01/the-one-correct-way-to-do-dependency-injection/

You can use it in your outer layers to get things built up and started, but don't call a dependency injection framework from your business logic, your inner layers.  All of your injected dependencies should be injected into the constructors so they will be obvious, not scattered throughout your code.