Answer by gnasher729 for How should I refactor a singleton (to be used by a...
"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...
View ArticleAnswer by Łukasz Zwierko for How should I refactor a singleton (to be used by...
"It has some initialization that used to be done in the constructor but it seems that this is generally frowned-on in the DI world" - that's not exactly true. DI is just about providing dependencies...
View ArticleAnswer by Euphoric for How should I refactor a singleton (to be used by a...
Not sure what language you are using, so I'm using pseudo-C# as example.You can create an IInitializes interface, which you then call after the instances are created.public interface IInitializes{ void...
View ArticleHow should I refactor a singleton (to be used by a container) when the...
I'm refactoring an old app to use dependency injection.n I'm pretty new to DI.I have a class that used to be a singleton. I'm refactoring it into a non-singleton class and using the container to manage...
View Article