Skip to content

Commit

Permalink
Update TargetFramework to net8.0 (#39)
Browse files Browse the repository at this point in the history
* - use net8.0
- update `Microsoft.EntityFrameworkCore` packages
- update `Utils.EnvironmentManager` package

* - update version and description
  • Loading branch information
ArdenHide authored Aug 30, 2024
1 parent c73b8f4 commit 12306b3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 25 deletions.
14 changes: 7 additions & 7 deletions ConfiguredSqlConnection/ConfiguredSqlConnection.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>5405e2de-7a05-4014-aea5-3ee845eb7fee</UserSecretsId>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>ConfiguredSqlConnection</Title>
<Version>1.1.5</Version>
<Version>1.2.0</Version>
<Authors>Senia,ArdenHide,Lomet</Authors>
<Company>The-Poolz</Company>
<PackageProjectUrl>https://www.nuget.org/packages/ConfiguredSqlConnection</PackageProjectUrl>
Expand All @@ -17,7 +17,7 @@
<Description>The NuGet package is a collection of utilities for working with SQL Server database connections using environment settings and secure connection strings.</Description>
<RepositoryUrl>https://github.com/The-Poolz/ConfiguredSqlConnection</RepositoryUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReleaseNotes>- Update packages version to newest.</PackageReleaseNotes>
<PackageReleaseNotes>https://github.com/The-Poolz/ConfiguredSqlConnection/releases/tag/v1.2.0</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -32,12 +32,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.14" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="SecretsManager" Version="1.0.0" />
<PackageReference Include="TestableDbContext.Mock" Version="1.0.0" />
<PackageReference Include="Utils.EnvironmentManager" Version="2.0.1" />
<PackageReference Include="Utils.EnvironmentManager" Version="4.0.1" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions ConfiguredSqlConnection/Extensions/ConnectionStringFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using SecretsManager;
using EnvironmentManager;
using System.ComponentModel;
using EnvironmentManager.Static;
using Microsoft.Extensions.Configuration;

namespace ConfiguredSqlConnection.Extensions;
Expand All @@ -17,7 +17,7 @@ public static string GetConnection(ContextOption option, string? dbName = null)

public static string GetConnectionFromSecret()
{
var secretValue = new EnvManager().GetEnvironmentValue<string>("CONFIGUREDSQLCONNECTION_SECRET_NAME_OF_CONNECTION", true);
var secretValue = EnvManager.Get<string>("CONFIGUREDSQLCONNECTION_SECRET_NAME_OF_CONNECTION", true);

return new SecretManager().GetSecretValue(secretValue, "connectionString");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ContextOption>("CONFIGUREDSQLCONNECTION_DB_MODE", true);
EnvManager.Get<ContextOption>("CONFIGUREDSQLCONNECTION_DB_MODE", true);
private static string DbName =>
envManager.GetEnvironmentValue<string>("CONFIGUREDSQLCONNECTION_DB_NAME");
EnvManager.Get<string>("CONFIGUREDSQLCONNECTION_DB_NAME");

public static string GetConnectionFromEnvironment() =>
ConnectionStringFactory.GetConnection(DbMode, DbName);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using EnvironmentManager;
using EnvironmentManager.Static;
using Microsoft.EntityFrameworkCore;

namespace ConfiguredSqlConnection.Extensions;
Expand All @@ -15,9 +15,8 @@ public DbContextEnvironmentFactory()
public DbContextEnvironmentFactory(DbContextOptionsBuilderFactory<TContext> optionsBuilderFactory)
: base(optionsBuilderFactory)
{
var envManager = new EnvManager();
dbMode = envManager.GetEnvironmentValue<ContextOption>("CONFIGUREDSQLCONNECTION_DB_MODE", true);
dbName = envManager.GetEnvironmentValue<string>("CONFIGUREDSQLCONNECTION_DB_NAME");
dbMode = EnvManager.Get<ContextOption>("CONFIGUREDSQLCONNECTION_DB_MODE", true);
dbName = EnvManager.Get<string>("CONFIGUREDSQLCONNECTION_DB_NAME");
}

public virtual TContext CreateFromEnvironment() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
using SecretsManager;
using EnvironmentManager;
using EnvironmentManager.Static;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;

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<string>("CONFIGUREDSQLCONNECTION_ACTION_CONNECTION");
var connectionString = EnvManager.Get<string>("CONFIGUREDSQLCONNECTION_ACTION_CONNECTION");
if (string.IsNullOrEmpty(connectionString)) return optionsBuilder;

optionsBuilder.UseSqlServer(connectionString, ConfigureSqlServerOptionsAction(migrationsAssembly));
Expand All @@ -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<string>("CONFIGUREDSQLCONNECTION_SECRET_NAME_OF_CONNECTION", true);
var secretValue = EnvManager.Get<string>("CONFIGUREDSQLCONNECTION_SECRET_NAME_OF_CONNECTION", true);
var connectionString = new SecretManager().GetSecretValue(secretValue, "connectionString");
if (string.IsNullOrEmpty(connectionString)) return optionsBuilder;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DbContextEnvironmentFactory<DbContext>>(optionsBuilderFactory);
Expand Down

0 comments on commit 12306b3

Please sign in to comment.