Quantcast
Channel: How should I refactor a singleton (to be used by a container) when the refactored class requires initialization and takes a dependency? - Software Engineering Stack Exchange
Viewing all articles
Browse latest Browse all 4

Answer by gnasher729 for How should I refactor a singleton (to be used by a container) when the refactored class requires initialization and takes a dependency?

$
0
0

"SRP says methods should do just one thing". True. Constructors should do just one thing, and that is to put the object into a usable state. If just storing the dependencies doesn't put the object into a usable state, then the constructor isn't doing it's job.

Did you read anywhere that "constructors with dependency injection should only set the dependencies, and shouldn't do anything else"? I don't think so.


Viewing all articles
Browse latest Browse all 4

Trending Articles