![]() Private static SelfHostService instance = null Public class SelfHostService : ServiceBase Lets have a look at a code which makes our class as singleton. So this makes a perfect scenario to expose our SelfHostService class as a singleton. In that post, WCF service is exposed to outside world, which can be accessed by many clients and messages received from all the requests are to be dispatched to SelfHostService class. In this post I had shown you how to host a WCF service in a window service. I am going to show example from my one of the post which I wrote. an instance of the class gets created when a request to get the instance has been initialized first time. I will create a private constructor of the class and will create a static property to get the access of the single instance of our class. ![]() There are many ways to create a class which returns a single instance. In such situations this pattern come in handy. ![]() Our code expects that every time an instance of the class gets created it should return only a single instance of the class. Sometimes we want to have only a single point access to the functionality of the class. Singleton design pattern is one of the creational design pattern, originally designed by Gang of Fours.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |