diff --git a/src/Volo.Abp.Settings/Volo/Abp/Settings/DefaultStoreSettingContributor.cs b/src/Volo.Abp.Settings/Volo/Abp/Settings/DefaultStoreSettingContributor.cs new file mode 100644 index 0000000000..170909fbe4 --- /dev/null +++ b/src/Volo.Abp.Settings/Volo/Abp/Settings/DefaultStoreSettingContributor.cs @@ -0,0 +1,19 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.Settings +{ + public class DefaultStoreSettingContributor : SettingContributor + { + public override string EntityType => null; + + public DefaultStoreSettingContributor(ISettingStore settingStore) + : base(settingStore) + { + } + + public override Task GetOrNullAsync(SettingDefinition setting, string entityId) + { + return SettingStore.GetOrNullAsync(setting.Name, null, null); + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Settings/Volo/Abp/Settings/DefaultValueSettingContributor.cs b/src/Volo.Abp.Settings/Volo/Abp/Settings/DefaultValueSettingContributor.cs new file mode 100644 index 0000000000..e32ad82a34 --- /dev/null +++ b/src/Volo.Abp.Settings/Volo/Abp/Settings/DefaultValueSettingContributor.cs @@ -0,0 +1,20 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.Settings +{ + public class DefaultValueSettingContributor : SettingContributor + { + public override string EntityType => null; + + public DefaultValueSettingContributor(ISettingStore settingStore) + : base(settingStore) + { + + } + + public override Task GetOrNullAsync(SettingDefinition setting, string entityId) + { + return Task.FromResult(setting.DefaultValue); + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingManager.cs b/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingManager.cs index 18ebba6cc0..5daf45266a 100644 --- a/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingManager.cs +++ b/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingManager.cs @@ -43,7 +43,9 @@ namespace Volo.Abp.Settings var setting = SettingDefinitionManager.Get(name); - foreach (var contributor in Enumerable.Reverse(Contributors.Value)) + var contributors = Enumerable.Reverse(Contributors.Value); + + foreach (var contributor in contributors) { var value = await contributor.GetOrNullAsync(setting, null); if (value != null) @@ -52,13 +54,7 @@ namespace Volo.Abp.Settings } } - var defaultStoreValue = await SettingStore.GetOrNullAsync(name, null, null); - if (defaultStoreValue != null) - { - return defaultStoreValue; - } - - return setting.DefaultValue; + return null; } public virtual async Task GetOrNullAsync(string name, string entityType, string entityId, bool fallback = true) @@ -68,27 +64,25 @@ namespace Volo.Abp.Settings var setting = SettingDefinitionManager.Get(name); - foreach (var contributor in GetFilteredContributors(entityType, fallback)) - { - var value = await contributor.GetOrNullAsync(setting, entityId); - if (value != null) - { - return value; - } - } + var contributors = Enumerable + .Reverse(Contributors.Value) + .SkipWhile(c => c.EntityType != entityType); if (!fallback) { - return null; + contributors = contributors.TakeWhile(c => c.EntityType == entityType); } - var defaultStoreValue = await SettingStore.GetOrNullAsync(name, null, null); - if (defaultStoreValue != null) + foreach (var contributor in contributors) { - return defaultStoreValue; + var value = await contributor.GetOrNullAsync(setting, entityId); + if (value != null) + { + return value; + } } - return setting.DefaultValue; + return null; } public Task> GetAllAsync() @@ -110,19 +104,5 @@ namespace Volo.Abp.Settings { throw new System.NotImplementedException(); } - - private IEnumerable GetFilteredContributors(string entityType, bool fallback) - { - var contributors = Enumerable - .Reverse(Contributors.Value) - .SkipWhile(c => c.EntityType != entityType); - - if (!fallback) - { - contributors = contributors.TakeWhile(c => c.EntityType == entityType); - } - - return contributors; - } } } \ No newline at end of file diff --git a/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingOptions.cs b/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingOptions.cs index eb4b65c44a..5e87bdcf0f 100644 --- a/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingOptions.cs +++ b/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingOptions.cs @@ -4,14 +4,18 @@ namespace Volo.Abp.Settings { public class SettingOptions { - public ITypeList Contributors { get; } - public ITypeList Providers { get; set; } + public ITypeList Contributors { get; } + public SettingOptions() { - Contributors = new TypeList(); Providers = new TypeList(); + Contributors = new TypeList + { + typeof(DefaultValueSettingContributor), + typeof(DefaultStoreSettingContributor) + }; } } }