Static constructors and sealed classes - how to make your code untestable
In almost all programming languages there is a possibility to put some application logic in static constructor. However, it's usually up to the platform to decide when to execute the code we put there - usually it happens when we the environment runs a piece of code that refers that class. Recently I was reading through the Windows Azure Training Kit (written by Microsoft) and this is a piece of code from the kit: public class GuestBookDataSource{ ... static GuestBookDataSource() { storageAccount = CloudStorageAccount .Parse(CloudConfigurationManager.GetSetting("DataConnectionString")); CloudTableClient cloudTableClient = storageAccount.CreateCloudTableClient(); CloudTable table = cloudTableClient.GetTableReference("GuestBookEntry"); table.CreateIfNotExists(); } ... } This code will open or create a cloud SQL table before accessing anything around it. As the code runs only once, it's seems like an efficient way to do the initialization of the ...