c# - Should i use property or Dictionary object for cashing config data -


i caching applications web.config key-value data singleton object can store config data in class properties or dictionary object. considering performance , flexibility not able decide between using dictionary or class properties.

  1. dictionary offers less changes whenever new key added/removed don't have make modifications singleton model logic whereas if use properties need manage additions/removal of respective key.
  2. while using dictionary need specify key name in string error prone , difficult manage.

based on above 2 reasons using dictionary storing cached data. please suggest if better solution exists here sample code.

public class configdata {     /// <summary>     /// configuration data     /// </summary>     public static readonly idictionary<string, string> configurationdata = new dictionary<string, string>();      /// <summary>     /// initializes <see cref="configdata" /> class.     /// </summary>     static configdata()     {         try         {             configurationdata = nvcextender.todictionary(configurationmanager.getsection("appsettings") namevaluecollection);         }         catch (exception ex)         {              throw;         }     } } 

configurationmanager.appsettings namevaluecollection , there little value in replacing own dictionary<string,string>.

representing appsettings properties of static or singleton class has number of benefits:

  • you can have validation , null checking in 1 place.
  • you can make properties strongly-typed
  • you can provide default values missing appsettings in 1 place.
  • you intellisense when accessing setting.

all design trade-off, whether or not these benefits justify effort of writing , maintaining static/singleton class judgement call. have internal static class in each assembly uses more 1 or 2 appsettings, strongly-typed property each appsetting used assembly.

if this, it's worth adopting naming convention it's clear appsettings belong assemblies, example "myassembly1.mysetting", "myassembly2.myothersetting".


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

unity3d - Fatal error- Monodevelop-Unity failed to start -