Skip to content

Commit

Permalink
Use ConnectionStringHelper when creating any repository derived from …
Browse files Browse the repository at this point in the history
…EFRepositoryBase
  • Loading branch information
artem-dudarev committed Aug 4, 2017
1 parent 1c6425a commit 37fda4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions VirtoCommerce.Platform.Core/Common/ConnectionStringHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ namespace VirtoCommerce.Platform.Core.Common
{
public class ConnectionStringHelper
{
public static string GetConnectionString(string name)
public static string GetConnectionString(string nameOrConnectionString)
{
var environmentConnectionString = Environment.GetEnvironmentVariable($"VIRTO_CONN_STR_{name}");
var result = nameOrConnectionString;

return !string.IsNullOrEmpty(environmentConnectionString)
? environmentConnectionString
: ConfigurationManager.ConnectionStrings[name]?.ConnectionString;
if (nameOrConnectionString.IndexOf('=') < 0)
{
result = Environment.GetEnvironmentVariable($"VIRTO_CONN_STR_{nameOrConnectionString}");

if (string.IsNullOrEmpty(result))
{
result = ConfigurationManager.ConnectionStrings[nameOrConnectionString]?.ConnectionString;
}
}

return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected EFRepositoryBase()
/// <param name="unitOfWork">The unit of work.</param>
/// <param name="interceptors">The interceptors.</param>
protected EFRepositoryBase(string nameOrConnectionString, IUnitOfWork unitOfWork = null, IInterceptor[] interceptors = null)
: base(nameOrConnectionString)
: base(ConnectionStringHelper.GetConnectionString(nameOrConnectionString))
{
_unitOfWork = unitOfWork;
_interceptors = interceptors;
Expand Down

0 comments on commit 37fda4d

Please sign in to comment.