The use of IOC (control inversion), rather than single, initiated upon first use, is beneficial for other reasons.
Syntactic initialization can suffer (famously) from multi-threaded problems when two threads try to access it for the first time at the same time. Subsequent access is likely to be correctly synchronized, but the first one is much more difficult to do.
Another huge advantage that I have found in using IOC is when an initialization error can occur. You do not want this to happen during the "first use", you want to know about this failure at an early stage, and, of course, it is easier to deal with this error.
Finally, in terms of testing, IOC provides an ideal model for isolating components, replacing them as needed, and combining various combinations more flexibly, thereby providing the perfect binding for unit testing and integration testing as a good rollback mechanism without actually returning any code at all.
The common reason singletones are used so often is not unity, but globality. If your project is managed correctly, you have one global object to which all the others are โregisteredโ (thus, your IOC model freezes) and are available worldwide, although it is still configurable.
source share