I think the solution you describe as SingletonFactory
is a ServiceLocator , and your singletones are services.
Is this solution acceptable?
It depends on how and where the Singletons are used. Singletones are not bad on their own if you isolate code that depends on them. Otherwise, you end up injecting a bunch of complex singletones every time you need test fixtures.
If you create an instance of Singletons instead of using static getters / seters, it will be more difficult to add a dependency without using the DI framework unless you pass single games to you, but then you can get a long list of options.
Is there a better / cleaner / shorter way to achieve the same effect?
IoC containers and DI frameworks (subtlety differs) are often used to manage dependencies that would otherwise be Loners. However, even if you eliminate the perversity of Singletons, itβs still good practice to try to isolate areas of dependence on specific services.
source share