Contact Us

Carmelo [email protected]

This section explored replacing the classic Singleton pattern with a standard instantiable class registered with a singleton lifetime. We looked at the old application state, learned that it was no more, and implemented two versions of it. We no longer need that, but it was a good way of learning about singletons.We then implemented a wishlist system as a second example. We concluded that the whole thing was working due to and managed by a single line of the composition root: the call to the AddSingleton method. Changing that line could drastically change the system’s behavior, making it unusable.From now on, you can see the Singleton pattern as an anti-pattern in .NET, and unless you find strong reasons to implement it, you should stick to normal classes and DI instead. Doing this moves the creation responsibility from the singleton class to the composition root, which is the composition root’s responsibility, leaving the class only one responsibility.Next, we explore the Service Locator anti-pattern/code smell.



         


          Terms of Use | Accessibility Privacy