mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#20527: Extending DefaultPlatformConfigurationAccessor to check for setting in ConnectionStrings and AppSettings
Work Item: 20527
This commit is contained in:
@@ -90,6 +90,7 @@
|
||||
<HintPath>..\..\..\..\lib\nhibernate\NHibernate.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.ApplicationServices" />
|
||||
<Reference Include="System.Web.Entity" />
|
||||
|
||||
@@ -1,21 +1,29 @@
|
||||
using Microsoft.WindowsAzure;
|
||||
using System.Configuration;
|
||||
|
||||
namespace Orchard.Azure.Services.Environment.Configuration {
|
||||
|
||||
public class DefaultPlatformConfigurationAccessor : IPlatformConfigurationAccessor {
|
||||
|
||||
/// <summary>
|
||||
/// Reads a setting from platform configuration, trying first prefixed with the current tenant name and
|
||||
/// secondly with no prefix.
|
||||
/// Trying to read a setting from the following sources in the following order (with and then without tenant name prefix):
|
||||
/// CloudConfigurationManager, ConnectionStrings, AppSettings.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the setting to read.</param>
|
||||
/// <param name="tenant">The curren tenant's name.</param>
|
||||
/// <param name="tenant">The current tenant's name.</param>
|
||||
/// <param name="namePrefix">An optional prefix to prepend the setting name with.</param>
|
||||
/// <returns>The value of the setting if found with or without tenant name prefix, otherwise null.</returns>
|
||||
/// <returns>The value of the setting if found in any of the available sources, otherwise null.</returns>
|
||||
public string GetSetting(string name, string tenant, string namePrefix = null) {
|
||||
var tenantName = tenant + ":" + (namePrefix ?? string.Empty) + name;
|
||||
var fallbackName = (namePrefix ?? string.Empty) + name;
|
||||
return CloudConfigurationManager.GetSetting(tenantName) ?? CloudConfigurationManager.GetSetting(fallbackName);
|
||||
|
||||
var settingFromCloudConfiguration = CloudConfigurationManager.GetSetting(tenantName) ?? CloudConfigurationManager.GetSetting(fallbackName);
|
||||
if (!string.IsNullOrEmpty(settingFromCloudConfiguration)) return settingFromCloudConfiguration;
|
||||
|
||||
var settingFromConnectionStrings = ConfigurationManager.ConnectionStrings[tenantName] ?? ConfigurationManager.ConnectionStrings[fallbackName];
|
||||
if (settingFromConnectionStrings != null) return settingFromConnectionStrings.ConnectionString;
|
||||
|
||||
return ConfigurationManager.AppSettings[tenantName] ?? ConfigurationManager.AppSettings[fallbackName];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/// Reads a setting using the available implementation(s).
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the setting to read.</param>
|
||||
/// <param name="tenant">The curren tenant's name.</param>
|
||||
/// <param name="tenant">The current tenant's name.</param>
|
||||
/// <param name="namePrefix">An optional prefix to prepend the setting name with.</param>
|
||||
/// <returns>The value of the setting if found with or without tenant name prefix, otherwise null.</returns>
|
||||
/// <see cref="DefaultPlatformConfigurationAccessor" />
|
||||
|
||||
Reference in New Issue
Block a user