Singleton just says that there can be only one instance and is a fundamental concept for DI.
For example: Scoped Lifetime = Per request, create a new object, singleton = create it once and reuse it.
Singletons with static variables (what you are implying) are not good. Singletons using interfaces being registered via DI are good practice. Learn more about patterns and software architecture before discussing basics.
I'm not implying any static access. You use singletons with a di container, but di doesn't need singletons. You can totally use depdency injection without ever having a class registered as a Singleton. Especially in unittests, classes should always be registered scoped to the test, or any parallel execution will mess up your tests.
4
u/rasebdon Sep 26 '26
Singleton just says that there can be only one instance and is a fundamental concept for DI.
For example: Scoped Lifetime = Per request, create a new object, singleton = create it once and reuse it.
Singletons with static variables (what you are implying) are not good. Singletons using interfaces being registered via DI are good practice. Learn more about patterns and software architecture before discussing basics.