...
The ConfigurationService is written with extensibility in mind. Though it defaults to the .NET local storage system, it is very easy to create a customized configuration service. Below is an example on how to customize the service so it reads and writes values from/to a database.
Code Block |
---|
public class DbConfigurationService : ConfigurationService { protected override bool ValueExists(string key) { using (var context = new ConfigurationContext()) { return (from config in context.Configurations where config.Key == key select config).Any(); } } protected override string GetValueFromStore(string key) { using (var context = new ConfigurationContext()) { return (from config in context.Configurations where config.Key == key select config.Value).First(); } } protected override void SetValueToStore(string key, string value) { using (var context = new ConfigurationContext()) { var configuration (from config in context.Configurations where config.Key == key select config).FirstOrDefault(); if (configuration == null) { configuration = context.CreateObject<Configuration>(); configuration.Key = key; } configuration.Value = value; context.SaveChanges(); } } } |
Note |
---|
Don't forget to register the customized ConfigurationService in the ServiceLocator |