.net - Performance issues with repeated calls to ConfigurationManager.AppSettings to get appsetting values? -


i'm working on code base has lot of identical configurationmanager.appsetting calls scattered throughout.

does sound possible performance issue?

or because data being small trivial , not 'expensive'? going file data, or .net runtime cache file/values/calls?

if isn't performance issue disorganized approach accessing application configuration values, , should re-factored cleaner , consistent implementation of accessing settings?

i it's more of code maintainability issue performance issue. simple dictionary lookup on appsettings isn't going problem unless have code tries perform lookup on appsettings in loop runs hundred times. surely such code cause performance problem. more important have configurationmanager.appsettings["mykey"] throughout codebase. introducing magic string. if have change key in configuration file, have thorough search , replace in projects. moreover, make decision based on value stored in appsettings. it's not straighforward read , use value as-is. take decision based on value. ex,

if (configurationmanager.appsettings["debugmode"] == "yes")   else   

you might repeating logic in hundred places. let's need add condition there:

if (configurationmanager.appsettings["debugmode"] == "yes" || configurationmanager.appsettings["internetnotavailable"] == "yes")   else   

this gets messy. code starts stink.

so, recommend dev team never use configurationmanager.appsettings anywhere in code. use static class read configuration values , such decisions precached single variable. ex,

static class confighelper {   private readonly static bool externalwebservicecallallowed = configuationmanager.appsettings["devmode"] == "false" && configurationmanager.appsettings["internetavailable"] == "true";  }  . . if (confighelper.externalwebservicecallallowed)    else    

this not better in performance, highly maintainable , extensible code.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -