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
Browsing all 4 articles
Browse latest View live

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 Article



Answer 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 Article

Answer 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 Article

How 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
Browsing all 4 articles
Browse latest View live




Latest Images