Differences

This shows you the differences between the selected revision and the current version of the page.

sharedinstance 2008/12/12 16:04 current
Line 1: Line 1:
 +====== SharedInstance<T> ======
 +SharedInstance is actually the most basic type of generic Singleton implementation that's been around in the C# community. This implementation was both simple and efficient. But, it violated the definition of a Singleton by depending on the presence of a public constructor and thereby allowing additional instances to be created. Therefore, I have refrained from calling this a Singleton resorted to the term SharedInstance.
 +
 +E.g:
 +<code c#>
 +SharedInstance<User>.Instance.Login("admin", "password");
 +
 +User employee1 = new User();
 +employee1.Username = "emp001";
 +employee1.Password = "pass001";
 +employee1.Save();
 +</code>
Back to top
sharedinstance.txt · Last modified: 2008/12/12 16:04 by sameeraperera