I hope I'm not late.
There are only a few relevant points to understand how this structure is created:
-Nop.Services.Configuration.ConfigurationProvider class -Nop.Services.Configuration.ISettingsService interface -Nop.Services.Configuration.SettingsService class
SettingsService provides only functions for saving and retrieving settings from repositories and implements some caching functions.
ConfigurationProvider does the actual magic.
Take a look at the BuildConfiguration
method:
// get properties we can write to var properties = from prop in typeof(TSettings).GetProperties() where prop.CanWrite && prop.CanRead let setting = _settingService.GetSettingByKey<string>(typeof(TSettings).Name + "." + prop.Name) where setting != null where CommonHelper.GetNopCustomTypeConverter(prop.PropertyType).CanConvertFrom(typeof(string)) where CommonHelper.GetNopCustomTypeConverter(prop.PropertyType).IsValid(setting) let value = CommonHelper.GetNopCustomTypeConverter(prop.PropertyType).ConvertFromInvariantString(setting) select new { prop, value };
Using reflection, * The settings class (for example, CustomerSettings) is checked and their properties are used to load the corresponding parameters from the service.
It then converts back the value stored as a string (you can check the NopCustomTypeConverter to see how serialization happens) and assign them back to the Entity setting:
properties.ToList().ForEach(p => p.prop.SetValue(Settings, p.value, null));
Another SaveSettings method (TSettings settings) does the exact opposite, takes a Setting object and breaks it, generating key and value pairs in the form of ClassName + Propertyvalues
It was implemented like this because it deploys concepts from IoC , separation of interfaces , n-level and other maintainability templates (based on API, ecc compliance check).
source share