mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-23 21:32:14 +08:00
Adding AppConfigurationAccessor to access appSettings or connectionStrings in an injected, loosely-coupled way.
Copied from Helpful Libraries, adapted to Orchard conventions.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Orchard.Environment.Configuration {
|
||||
public class AppConfigurationAccessor : IAppConfigurationAccessor {
|
||||
public string GetConfiguration(string name) {
|
||||
var appSettingsValue = ConfigurationManager.AppSettings[name];
|
||||
if (appSettingsValue != null) {
|
||||
return appSettingsValue;
|
||||
}
|
||||
|
||||
var connectionStringSettings = ConfigurationManager.ConnectionStrings[name];
|
||||
if (connectionStringSettings != null) {
|
||||
return connectionStringSettings.ConnectionString;
|
||||
}
|
||||
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Orchard.Environment.Configuration {
|
||||
/// <summary>
|
||||
/// Exposes application configuration (can be e.g. AppSettings from Web.config or CloudConfiguration on Azure).
|
||||
/// </summary>
|
||||
public interface IAppConfigurationAccessor : IDependency {
|
||||
/// <summary>
|
||||
/// Gets an application configuration value with the given name (can be e.g. AppSettings from Web.config or CloudConfiguration on Azure).
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the application configuration entry.</param>
|
||||
/// <returns>The string value of the application configuration entry.</returns>
|
||||
string GetConfiguration(string name);
|
||||
}
|
||||
}
|
||||
@@ -225,6 +225,8 @@
|
||||
<Compile Include="Environment\AutofacUtil\ConfigurationSettingsReaderConstants.cs" />
|
||||
<Compile Include="Environment\CollectionOrderModule.cs" />
|
||||
<Compile Include="Caching\DefaultAsyncTokenProvider.cs" />
|
||||
<Compile Include="Environment\Configuration\AppConfigurationAccessor.cs" />
|
||||
<Compile Include="Environment\Configuration\IAppConfigurationAccessor.cs" />
|
||||
<Compile Include="Environment\Configuration\ShellSettingsSerializer.cs" />
|
||||
<Compile Include="Environment\Extensions\DefaultCriticalErrorProvider.cs" />
|
||||
<Compile Include="Environment\Extensions\ExtensionMonitoringCoordinator.cs" />
|
||||
|
||||
Reference in New Issue
Block a user