-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolved #2159: Create Configuration setting value provider.
- Loading branch information
Showing
8 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
framework/src/Volo.Abp.Settings/Volo/Abp/Settings/ConfigurationSettingValueProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
using Volo.Abp.DependencyInjection; | ||
|
||
namespace Volo.Abp.Settings | ||
{ | ||
public class ConfigurationSettingValueProvider : ISettingValueProvider, ITransientDependency | ||
{ | ||
public const string ConfigurationNamePrefix = "Settings:"; | ||
|
||
public const string ProviderName = "C"; | ||
|
||
public string Name => ProviderName; | ||
|
||
protected IConfiguration Configuration { get; } | ||
|
||
public ConfigurationSettingValueProvider(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public virtual Task<string> GetOrNullAsync(SettingDefinition setting) | ||
{ | ||
return Task.FromResult(Configuration[ConfigurationNamePrefix + setting.Name]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...ingManagement.Domain/Volo/Abp/SettingManagement/ConfigurationSettingManagementProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
using Volo.Abp.DependencyInjection; | ||
using Volo.Abp.Settings; | ||
|
||
namespace Volo.Abp.SettingManagement | ||
{ | ||
public class ConfigurationSettingManagementProvider : ISettingManagementProvider, ITransientDependency | ||
{ | ||
public string Name => ConfigurationSettingValueProvider.ProviderName; | ||
|
||
protected IConfiguration Configuration { get; } | ||
|
||
public ConfigurationSettingManagementProvider(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public Task<string> GetOrNullAsync(SettingDefinition setting, string providerKey) | ||
{ | ||
return Task.FromResult(Configuration[ConfigurationSettingValueProvider.ConfigurationNamePrefix + setting.Name]); | ||
} | ||
|
||
public Task SetAsync(SettingDefinition setting, string value, string providerKey) | ||
{ | ||
throw new AbpException($"Can not set a setting value to the application configuration."); | ||
} | ||
|
||
public Task ClearAsync(SettingDefinition setting, string providerKey) | ||
{ | ||
throw new AbpException($"Can not set a setting value to the application configuration."); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...anagement.Domain/Volo/Abp/SettingManagement/ConfigurationValueSettingManagerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using JetBrains.Annotations; | ||
using Volo.Abp.Settings; | ||
|
||
namespace Volo.Abp.SettingManagement | ||
{ | ||
public static class ConfigurationValueSettingManagerExtensions | ||
{ | ||
public static Task<string> GetOrNullConfigurationAsync(this ISettingManager settingManager, [NotNull] string name, bool fallback = true) | ||
{ | ||
return settingManager.GetOrNullAsync(name, ConfigurationSettingValueProvider.ProviderName, null, fallback); | ||
} | ||
|
||
public static Task<List<SettingValue>> GetAllConfigurationAsync(this ISettingManager settingManager, bool fallback = true) | ||
{ | ||
return settingManager.GetAllAsync(ConfigurationSettingValueProvider.ProviderName, null, fallback); | ||
} | ||
} | ||
} |
5 changes: 1 addition & 4 deletions
5
...anagement.Tests/Volo/Abp/SettingManagement/DefaultValueSettingManagementProvider_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters