Ways of keeping configuration code out of logic code using Dependency Injection

Configuration classes reduce cohension and increase coupling in the consumers. This is because there may be many settings that don’t relate to the one or two needed by your class, yet in order to fulfill the dependency, your implementation of IConfiguration must supply values for all of the accessors, even the irrelevant ones. It also … Read more

FileNotFoundException in ApplicationSettingsBase

Just an explanation for why this exception is thrown. You can repro the exception with this sample Windows Forms app. Start by adding a setting named “Setting” of type StringCollection. Click the dots in the Value column and enter a couple of strings. Make the form class code look like this: public partial class Form1 … Read more

How do I store desktop application data in a cross platform way for python?

Well, I hate to have been the one to answer my own question, but no one else seems to know. I’m leaving the answer for posterity. APPNAME = “MyApp” import sys from os import path, environ if sys.platform == ‘darwin’: from AppKit import NSSearchPathForDirectoriesInDomains # http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/func/NSSearchPathForDirectoriesInDomains # NSApplicationSupportDirectory = 14 # NSUserDomainMask = 1 # … Read more

Find current country from iPhone device

To find the country of the user’s chosen language: NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale. NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; // get country code, e.g. ES (Spain), FR (France), etc. In Swift: let currentLocale = NSLocale.currentLocale() let countryCode = currentLocale.objectForKey(NSLocaleCountryCode) as? String If you want to find the country code of … Read more

Difference between ‘SpecialFolder.LocalApplicationData’ and ‘SpecialFolder.ApplicationData’?

The Roaming folder is copied between machines when roaming profiles are enabled (in a domain environment). Use it for application data that you want to share between machines. But don’t store large files in there — IT departments don’t like it when you do that, and it increases the time taken for the user to … Read more

Which design patterns can be applied to the configuration settings problem?

I prefer to create an interface for setting query, loading, and saving. By using dependency injection, I can inject this into each component that requires it. This allows flexibility in terms of replacing the configuration strategy, and gives a common base for everything to work from. I prefer this to a single, global “settings loader” … Read more

tech