I want to understand what is the difference between AddSingleton<>()
method implementation in .NET Core, and the method implementation if singleton object creation in C#?
Asked
Active
Viewed 36 times
0

marc_s
- 732,580
- 175
- 1,330
- 1,459

Kunal Relan
- 279
- 3
- 8
-
2To use or not to use the DI, that's the question. – Reza Aghaei Jan 24 '22 at 12:20
-
`AddSingleton` method tells the DI to create only one object of the registered class is created when resolved at runtime. How it is done by the DI, we don't need to worry about it. Singleton pattern implemented by ourselves involves private constructor, static property etc. They are not needed whey register as singleton in DI. – Chetan Jan 24 '22 at 12:22