3 ms·
I would consider creating a dependency as a singleton in your composition root different from a "true" singleton, because the latter involves baking the assumpt
by emodendroket 5y ago
I would consider creating a dependency as a singleton in your composition root different from a "true" singleton, because the latter involves baking the assumption that it will be a singleton into all callers rather than injecting it.
- Matthias247 5y agoI guess so. My favorite problem with singletons is testability. How can you properly mock/observe/etc it inside a test case, if lots of test-cases are executed in parallel. With a real global object it can be tricky. But if the object is not global because an IOC container might still create a fresh one per test, it wouldn't be an issue.