I would like to add singleton object to MVC application (for learning purposes). I'd prefer to instantiate singleton object somewhere in Application_Start()
method and then for example access it in controller. I don't want to use other libraries, like unity. Is there any way to do so?
Asked
Active
Viewed 707 times
0

Mazas
- 197
- 3
- 10
-
What does the singleton pattern have *anything* to do with asp.net-mvc? – Erik Philips Dec 01 '17 at 18:24
-
The point of using singleton is you don't need to instantiate it outside of its own class.. – FCin Dec 01 '17 at 18:24
-
@FCin, not necessarily. There are situations where the instantiation may happen later or outside the class itself. The pattern specifies only that there's just one instance, not how or where it is created. – DiskJunky Dec 01 '17 at 18:42
-
This is arguably not a duplicate in that the OP is requesting the instantiation to happen outside the class itself, in the `Application_Start`. This is not addressed in the linked post as a duplicate. – DiskJunky Dec 01 '17 at 18:45