From 37fda4d4d52e2e2c0806944bb08a648d5d1636ee Mon Sep 17 00:00:00 2001 From: artem-dudarev Date: Fri, 4 Aug 2017 16:32:19 +0200 Subject: [PATCH] Use ConnectionStringHelper when creating any repository derived from EFRepositoryBase --- .../Common/ConnectionStringHelper.cs | 18 +++++++++++++----- .../Infrastructure/EFRepositoryBase.cs | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/VirtoCommerce.Platform.Core/Common/ConnectionStringHelper.cs b/VirtoCommerce.Platform.Core/Common/ConnectionStringHelper.cs index c4234196a60..f166afa466a 100644 --- a/VirtoCommerce.Platform.Core/Common/ConnectionStringHelper.cs +++ b/VirtoCommerce.Platform.Core/Common/ConnectionStringHelper.cs @@ -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; } } } diff --git a/VirtoCommerce.Platform.Data/Infrastructure/EFRepositoryBase.cs b/VirtoCommerce.Platform.Data/Infrastructure/EFRepositoryBase.cs index a0180048b8d..e574dabfbaa 100644 --- a/VirtoCommerce.Platform.Data/Infrastructure/EFRepositoryBase.cs +++ b/VirtoCommerce.Platform.Data/Infrastructure/EFRepositoryBase.cs @@ -38,7 +38,7 @@ protected EFRepositoryBase() /// The unit of work. /// The interceptors. protected EFRepositoryBase(string nameOrConnectionString, IUnitOfWork unitOfWork = null, IInterceptor[] interceptors = null) - : base(nameOrConnectionString) + : base(ConnectionStringHelper.GetConnectionString(nameOrConnectionString)) { _unitOfWork = unitOfWork; _interceptors = interceptors;