{"id":152,"date":"2008-08-22T06:57:51","date_gmt":"2008-08-22T05:57:51","guid":{"rendered":"http:\/\/thekua.com\/atwork\/2008\/08\/22\/treat-your-appconfig-like-a-global-variable\/"},"modified":"2008-08-22T09:36:15","modified_gmt":"2008-08-22T08:36:15","slug":"treat-your-appconfig-like-a-global-variable","status":"publish","type":"post","link":"https:\/\/thekua.com\/atwork\/2008\/08\/treat-your-appconfig-like-a-global-variable\/","title":{"rendered":"Treat your App.config like a global variable"},"content":{"rendered":"<p>I remember looking at a few codebases in C# and it surprised me how many people encapsulate some of their system well, yet treat their application configuration as a different thing. Many times I&#8217;ve seen code that looks like: <code>ConfigurationSettings.AppSettings[\"DatabaseConnectionString\"]; <\/code> alongside the thing that is using it. In fact, I often see this code repeated in various parts of the system wherever anyone needs to draw on application configuration.<\/p>\n<p><strong>Global variables are bad<\/strong><br \/>\nMost good programmers seem to realise that most global variables are bad, yet this is exactly what I think accessing the application configuration is like. If you want to change the way your configuration is loaded (i.e. programmatically or from a database) think of how many places you now need to change it, let alone how it effects the order in which you instantiate objects.<\/p>\n<p><strong>My advice: Separate the use of configuration from where it declared<\/strong><br \/>\nI try to follow the pattern isolating the configuration into a single class depending on the access method, such as:<\/p>\n<ul>\n<li><code>DatabaseBackedConfiguration<\/code><\/li>\n<li><code>FileBackedConfiguration<\/code> <\/li>\n<li><code>DefaultInMemoryBackedConfiguration<\/code><\/li>\n<\/ul>\n<p>Each of these classes them implement several roles depending on what configuration they might provide such as: <\/p>\n<ul>\n<li><code>HibernateConfiguration<\/code><\/li>\n<li><code>ApplicationConfiguration<\/code><\/li>\n<li><code>ArchivingConfiguration<\/code><\/li>\n<\/ul>\n<p>Having smaller roles makes it clearer what sort of configuration is really needed for a particular consumer, and it allows me to change the decision about how that configuration is now provided to it. It enables me to do things like specify different environment configurations and do so in the method that I prefer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I remember looking at a few codebases in C# and it surprised me how many people encapsulate some of their system well, yet treat their application configuration as a different thing. Many times I&#8217;ve seen code that looks like: ConfigurationSettings.AppSettings[&#8220;DatabaseConnectionString&#8221;]; alongside the thing that is using it. In fact, I often see this code repeated [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,4],"tags":[],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-net","category-development","post-preview"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Treat your App.config like a global variable - patkua@work<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thekua.com\/atwork\/2008\/08\/treat-your-appconfig-like-a-global-variable\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Treat your App.config like a global variable - patkua@work\" \/>\n<meta property=\"og:description\" content=\"I remember looking at a few codebases in C# and it surprised me how many people encapsulate some of their system well, yet treat their application configuration as a different thing. Many times I&#8217;ve seen code that looks like: ConfigurationSettings.AppSettings[&quot;DatabaseConnectionString&quot;]; alongside the thing that is using it. In fact, I often see this code repeated [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thekua.com\/atwork\/2008\/08\/treat-your-appconfig-like-a-global-variable\/\" \/>\n<meta property=\"og:site_name\" content=\"patkua@work\" \/>\n<meta property=\"article:published_time\" content=\"2008-08-22T05:57:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2008-08-22T08:36:15+00:00\" \/>\n<meta name=\"author\" content=\"Patrick\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@patkua\" \/>\n<meta name=\"twitter:site\" content=\"@patkua\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Patrick\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/08\\\/treat-your-appconfig-like-a-global-variable\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/08\\\/treat-your-appconfig-like-a-global-variable\\\/\"},\"author\":{\"name\":\"Patrick\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#\\\/schema\\\/person\\\/c942203c9ed3ff9e21c6c49a996ea3ae\"},\"headline\":\"Treat your App.config like a global variable\",\"datePublished\":\"2008-08-22T05:57:51+00:00\",\"dateModified\":\"2008-08-22T08:36:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/08\\\/treat-your-appconfig-like-a-global-variable\\\/\"},\"wordCount\":249,\"commentCount\":4,\"articleSection\":[\".Net\",\"Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/08\\\/treat-your-appconfig-like-a-global-variable\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/08\\\/treat-your-appconfig-like-a-global-variable\\\/\",\"url\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/08\\\/treat-your-appconfig-like-a-global-variable\\\/\",\"name\":\"Treat your App.config like a global variable - patkua@work\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#website\"},\"datePublished\":\"2008-08-22T05:57:51+00:00\",\"dateModified\":\"2008-08-22T08:36:15+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#\\\/schema\\\/person\\\/c942203c9ed3ff9e21c6c49a996ea3ae\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/08\\\/treat-your-appconfig-like-a-global-variable\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/08\\\/treat-your-appconfig-like-a-global-variable\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/08\\\/treat-your-appconfig-like-a-global-variable\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Treat your App.config like a global variable\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#website\",\"url\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/\",\"name\":\"patkua@work\",\"description\":\"The intersection of technology and leadership\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#\\\/schema\\\/person\\\/c942203c9ed3ff9e21c6c49a996ea3ae\",\"name\":\"Patrick\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g\",\"caption\":\"Patrick\"},\"sameAs\":[\"http:\\\/\\\/thekua.com\\\/atwork\"],\"url\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/author\\\/patrick\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Treat your App.config like a global variable - patkua@work","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/thekua.com\/atwork\/2008\/08\/treat-your-appconfig-like-a-global-variable\/","og_locale":"en_US","og_type":"article","og_title":"Treat your App.config like a global variable - patkua@work","og_description":"I remember looking at a few codebases in C# and it surprised me how many people encapsulate some of their system well, yet treat their application configuration as a different thing. Many times I&#8217;ve seen code that looks like: ConfigurationSettings.AppSettings[\"DatabaseConnectionString\"]; alongside the thing that is using it. In fact, I often see this code repeated [&hellip;]","og_url":"https:\/\/thekua.com\/atwork\/2008\/08\/treat-your-appconfig-like-a-global-variable\/","og_site_name":"patkua@work","article_published_time":"2008-08-22T05:57:51+00:00","article_modified_time":"2008-08-22T08:36:15+00:00","author":"Patrick","twitter_card":"summary_large_image","twitter_creator":"@patkua","twitter_site":"@patkua","twitter_misc":{"Written by":"Patrick","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/thekua.com\/atwork\/2008\/08\/treat-your-appconfig-like-a-global-variable\/#article","isPartOf":{"@id":"https:\/\/thekua.com\/atwork\/2008\/08\/treat-your-appconfig-like-a-global-variable\/"},"author":{"name":"Patrick","@id":"https:\/\/thekua.com\/atwork\/#\/schema\/person\/c942203c9ed3ff9e21c6c49a996ea3ae"},"headline":"Treat your App.config like a global variable","datePublished":"2008-08-22T05:57:51+00:00","dateModified":"2008-08-22T08:36:15+00:00","mainEntityOfPage":{"@id":"https:\/\/thekua.com\/atwork\/2008\/08\/treat-your-appconfig-like-a-global-variable\/"},"wordCount":249,"commentCount":4,"articleSection":[".Net","Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/thekua.com\/atwork\/2008\/08\/treat-your-appconfig-like-a-global-variable\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/thekua.com\/atwork\/2008\/08\/treat-your-appconfig-like-a-global-variable\/","url":"https:\/\/thekua.com\/atwork\/2008\/08\/treat-your-appconfig-like-a-global-variable\/","name":"Treat your App.config like a global variable - patkua@work","isPartOf":{"@id":"https:\/\/thekua.com\/atwork\/#website"},"datePublished":"2008-08-22T05:57:51+00:00","dateModified":"2008-08-22T08:36:15+00:00","author":{"@id":"https:\/\/thekua.com\/atwork\/#\/schema\/person\/c942203c9ed3ff9e21c6c49a996ea3ae"},"breadcrumb":{"@id":"https:\/\/thekua.com\/atwork\/2008\/08\/treat-your-appconfig-like-a-global-variable\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thekua.com\/atwork\/2008\/08\/treat-your-appconfig-like-a-global-variable\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/thekua.com\/atwork\/2008\/08\/treat-your-appconfig-like-a-global-variable\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/thekua.com\/atwork\/"},{"@type":"ListItem","position":2,"name":"Treat your App.config like a global variable"}]},{"@type":"WebSite","@id":"https:\/\/thekua.com\/atwork\/#website","url":"https:\/\/thekua.com\/atwork\/","name":"patkua@work","description":"The intersection of technology and leadership","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/thekua.com\/atwork\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/thekua.com\/atwork\/#\/schema\/person\/c942203c9ed3ff9e21c6c49a996ea3ae","name":"Patrick","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g","caption":"Patrick"},"sameAs":["http:\/\/thekua.com\/atwork"],"url":"https:\/\/thekua.com\/atwork\/author\/patrick\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":0,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"wp:attachment":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}