diff --git a/ConfiguredSqlConnection/ConfiguredSqlConnection.csproj b/ConfiguredSqlConnection/ConfiguredSqlConnection.csproj index 4a1063b..f6e7c7c 100644 --- a/ConfiguredSqlConnection/ConfiguredSqlConnection.csproj +++ b/ConfiguredSqlConnection/ConfiguredSqlConnection.csproj @@ -1,13 +1,13 @@  - net6.0 + net8.0 enable enable 5405e2de-7a05-4014-aea5-3ee845eb7fee True ConfiguredSqlConnection - 1.1.5 + 1.2.0 Senia,ArdenHide,Lomet The-Poolz https://www.nuget.org/packages/ConfiguredSqlConnection @@ -17,7 +17,7 @@ The NuGet package is a collection of utilities for working with SQL Server database connections using environment settings and secure connection strings. https://github.com/The-Poolz/ConfiguredSqlConnection LICENSE - - Update packages version to newest. + https://github.com/The-Poolz/ConfiguredSqlConnection/releases/tag/v1.2.0 @@ -32,12 +32,12 @@ - - - + + + - + diff --git a/ConfiguredSqlConnection/Extensions/ConnectionStringFactory.cs b/ConfiguredSqlConnection/Extensions/ConnectionStringFactory.cs index 1a78757..a599593 100644 --- a/ConfiguredSqlConnection/Extensions/ConnectionStringFactory.cs +++ b/ConfiguredSqlConnection/Extensions/ConnectionStringFactory.cs @@ -1,6 +1,6 @@ using SecretsManager; -using EnvironmentManager; using System.ComponentModel; +using EnvironmentManager.Static; using Microsoft.Extensions.Configuration; namespace ConfiguredSqlConnection.Extensions; @@ -17,7 +17,7 @@ public static string GetConnection(ContextOption option, string? dbName = null) public static string GetConnectionFromSecret() { - var secretValue = new EnvManager().GetEnvironmentValue("CONFIGUREDSQLCONNECTION_SECRET_NAME_OF_CONNECTION", true); + var secretValue = EnvManager.Get("CONFIGUREDSQLCONNECTION_SECRET_NAME_OF_CONNECTION", true); return new SecretManager().GetSecretValue(secretValue, "connectionString"); } diff --git a/ConfiguredSqlConnection/Extensions/ConnectionStringFromEnvironmentFactory.cs b/ConfiguredSqlConnection/Extensions/ConnectionStringFromEnvironmentFactory.cs index b59ecff..cad39e7 100644 --- a/ConfiguredSqlConnection/Extensions/ConnectionStringFromEnvironmentFactory.cs +++ b/ConfiguredSqlConnection/Extensions/ConnectionStringFromEnvironmentFactory.cs @@ -1,15 +1,14 @@ -using EnvironmentManager; +using EnvironmentManager.Static; namespace ConfiguredSqlConnection.Extensions; public static class ConnectionStringFromEnvironmentFactory { - private static readonly EnvManager envManager = new(); private static ContextOption DbMode => - envManager.GetEnvironmentValue("CONFIGUREDSQLCONNECTION_DB_MODE", true); + EnvManager.Get("CONFIGUREDSQLCONNECTION_DB_MODE", true); private static string DbName => - envManager.GetEnvironmentValue("CONFIGUREDSQLCONNECTION_DB_NAME"); + EnvManager.Get("CONFIGUREDSQLCONNECTION_DB_NAME"); public static string GetConnectionFromEnvironment() => ConnectionStringFactory.GetConnection(DbMode, DbName); -} +} \ No newline at end of file diff --git a/ConfiguredSqlConnection/Extensions/DbContextEnvironmentFactory.cs b/ConfiguredSqlConnection/Extensions/DbContextEnvironmentFactory.cs index c06329d..496d7f9 100644 --- a/ConfiguredSqlConnection/Extensions/DbContextEnvironmentFactory.cs +++ b/ConfiguredSqlConnection/Extensions/DbContextEnvironmentFactory.cs @@ -1,4 +1,4 @@ -using EnvironmentManager; +using EnvironmentManager.Static; using Microsoft.EntityFrameworkCore; namespace ConfiguredSqlConnection.Extensions; @@ -15,9 +15,8 @@ public DbContextEnvironmentFactory() public DbContextEnvironmentFactory(DbContextOptionsBuilderFactory optionsBuilderFactory) : base(optionsBuilderFactory) { - var envManager = new EnvManager(); - dbMode = envManager.GetEnvironmentValue("CONFIGUREDSQLCONNECTION_DB_MODE", true); - dbName = envManager.GetEnvironmentValue("CONFIGUREDSQLCONNECTION_DB_NAME"); + dbMode = EnvManager.Get("CONFIGUREDSQLCONNECTION_DB_MODE", true); + dbName = EnvManager.Get("CONFIGUREDSQLCONNECTION_DB_NAME"); } public virtual TContext CreateFromEnvironment() => diff --git a/ConfiguredSqlConnection/Extensions/DbContextOptionsBuilderExtensions.cs b/ConfiguredSqlConnection/Extensions/DbContextOptionsBuilderExtensions.cs index a414a1e..f9cd69d 100644 --- a/ConfiguredSqlConnection/Extensions/DbContextOptionsBuilderExtensions.cs +++ b/ConfiguredSqlConnection/Extensions/DbContextOptionsBuilderExtensions.cs @@ -1,5 +1,5 @@ using SecretsManager; -using EnvironmentManager; +using EnvironmentManager.Static; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -7,12 +7,10 @@ namespace ConfiguredSqlConnection.Extensions; public static class DbContextOptionsBuilderExtensions { - private static readonly EnvManager envManager = new(); - public static DbContextOptionsBuilder ConfigureFromActionConnection(this DbContextOptionsBuilder optionsBuilder, string? migrationsAssembly = null) { if (optionsBuilder.IsConfigured) return optionsBuilder; - var connectionString = envManager.GetEnvironmentValue("CONFIGUREDSQLCONNECTION_ACTION_CONNECTION"); + var connectionString = EnvManager.Get("CONFIGUREDSQLCONNECTION_ACTION_CONNECTION"); if (string.IsNullOrEmpty(connectionString)) return optionsBuilder; optionsBuilder.UseSqlServer(connectionString, ConfigureSqlServerOptionsAction(migrationsAssembly)); @@ -23,7 +21,7 @@ public static DbContextOptionsBuilder ConfigureFromActionConnection(this DbConte public static DbContextOptionsBuilder ConfigureFromSecretConnection(this DbContextOptionsBuilder optionsBuilder, string? migrationsAssembly = null) { if (optionsBuilder.IsConfigured) return optionsBuilder; - var secretValue = envManager.GetEnvironmentValue("CONFIGUREDSQLCONNECTION_SECRET_NAME_OF_CONNECTION", true); + var secretValue = EnvManager.Get("CONFIGUREDSQLCONNECTION_SECRET_NAME_OF_CONNECTION", true); var connectionString = new SecretManager().GetSecretValue(secretValue, "connectionString"); if (string.IsNullOrEmpty(connectionString)) return optionsBuilder; diff --git a/ConfiguredSqlConnectionTests/ConfiguredSqlConnectionTests.csproj b/ConfiguredSqlConnectionTests/ConfiguredSqlConnectionTests.csproj index 5f79bbb..3f9a57c 100644 --- a/ConfiguredSqlConnectionTests/ConfiguredSqlConnectionTests.csproj +++ b/ConfiguredSqlConnectionTests/ConfiguredSqlConnectionTests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable diff --git a/ConfiguredSqlConnectionTests/ExtensionsTests/FactoriesTests.cs b/ConfiguredSqlConnectionTests/ExtensionsTests/FactoriesTests.cs index 46dd90c..ce29c5c 100644 --- a/ConfiguredSqlConnectionTests/ExtensionsTests/FactoriesTests.cs +++ b/ConfiguredSqlConnectionTests/ExtensionsTests/FactoriesTests.cs @@ -49,7 +49,7 @@ public void CreateFromEnvironment() [Fact] public void CreateFromEnvironment_OptionNotSet_ThrowException() { - var expectedExceptionMessage = $"Environment variable 'CONFIGUREDSQLCONNECTION_DB_MODE' is null or empty."; + var expectedExceptionMessage = "Environment variable 'CONFIGUREDSQLCONNECTION_DB_MODE' is null or empty. (Parameter 'envValue')"; Environment.SetEnvironmentVariable("CONFIGUREDSQLCONNECTION_DB_MODE", $""); Environment.SetEnvironmentVariable("CONFIGUREDSQLCONNECTION_DB_NAME", $""); var factory = new Mock>(optionsBuilderFactory);