Created
May 23, 2012 19:12
-
-
Save SyntaxC4/2777165 to your computer and use it in GitHub Desktop.
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
// Developer: Cory Fowler | |
// | |
namespace Net.SyntaxC4.Helpers | |
{ | |
using System.Configuration; | |
using Microsoft.WindowsAzure.ServiceRuntime; | |
/// <summary> | |
/// Provides a way of Providing Context between Cloud and On-Premise Deployment of an Application. | |
/// </summary> | |
public class ConnectionStringResolver | |
{ | |
private string _connectionString; | |
private string _cloudConnectionString; | |
private string _localConnectionString; | |
public string ConnectionString | |
{ | |
get | |
{ | |
if (string.IsNullOrWhiteSpace(_connectionString)) | |
{ | |
_connectionString = (RoleEnvironment.IsAvailable) | |
? RoleEnvironment.GetConfigurationSettingValue(_cloudConnectionString) | |
: ConfigurationManager.ConnectionStrings[_localConnectionString].ConnectionString; | |
} | |
return _connectionString; | |
} | |
} | |
public static ConnectionStringResolver Create() | |
{ | |
return new ConnectionStringResolver(); | |
} | |
public ConnectionStringResolver WithCloudConnectionStringName(string settingName) | |
{ | |
_cloudConnectionString = settingName; | |
return this; | |
} | |
public ConnectionStringResolver WithLocalConnectionStringName(string settingName) | |
{ | |
_localConnectionString = settingName; | |
return this; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment