Skip to content

Commit

Permalink
- cleanup
Browse files Browse the repository at this point in the history
- update `README`
- update .csproj
  • Loading branch information
ArdenHide committed Nov 14, 2023
1 parent ed81801 commit 4c7d8d4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
4 changes: 2 additions & 2 deletions ConfiguredSqlConnection/ConfiguredSqlConnection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<UserSecretsId>5405e2de-7a05-4014-aea5-3ee845eb7fee</UserSecretsId>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>ConfiguredSqlConnection</Title>
<Version>1.1.3</Version>
<Version>1.1.4</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 package `Utils.EnvironmentManager` to `2.0.1`</PackageReleaseNotes>
<PackageReleaseNotes>- Updated `ConfigureFromActionConnection`, added possible to pass assymbly of migrations project.</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using SecretsManager;
using EnvironmentManager;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace ConfiguredSqlConnection.Extensions;

Expand All @@ -15,14 +15,7 @@ public static DbContextOptionsBuilder ConfigureFromActionConnection(this DbConte
var connectionString = envManager.GetEnvironmentValue<string>("CONFIGUREDSQLCONNECTION_ACTION_CONNECTION");
if (string.IsNullOrEmpty(connectionString)) return optionsBuilder;

if (string.IsNullOrWhiteSpace(migrationsAssembly))
{
optionsBuilder.UseSqlServer(connectionString);
}
else
{
optionsBuilder.UseSqlServer(connectionString, options => options.MigrationsAssembly(migrationsAssembly));
}
optionsBuilder.UseSqlServer(connectionString, ConfigureSqlServerOptionsAction(migrationsAssembly));

return optionsBuilder;
}
Expand All @@ -34,15 +27,13 @@ public static DbContextOptionsBuilder ConfigureFromSecretConnection(this DbConte
var connectionString = new SecretManager().GetSecretValue(secretValue, "connectionString");
if (string.IsNullOrEmpty(connectionString)) return optionsBuilder;

if (string.IsNullOrWhiteSpace(migrationsAssembly))
{
optionsBuilder.UseSqlServer(connectionString);
}
else
{
optionsBuilder.UseSqlServer(connectionString, options => options.MigrationsAssembly(migrationsAssembly));
}
optionsBuilder.UseSqlServer(connectionString, ConfigureSqlServerOptionsAction(migrationsAssembly));

return optionsBuilder;
}

private static Action<SqlServerDbContextOptionsBuilder>? ConfigureSqlServerOptionsAction(string? migrationsAssembly = null) =>
!string.IsNullOrWhiteSpace(migrationsAssembly)
? options => options.MigrationsAssembly(migrationsAssembly)
: null;
}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ optionsBuilder
.ConfigureFromActionConnection()
.ConfigureFromSecretConnection();

// Try to configure action connection also try to configure db connection via SecretManager.
// Try to configure action connection, with migration assembly
// also try to configure db connection via SecretManager with migration assembly.
optionsBuilder
.ConfigureFromActionConnection()
.ConfigureFromSecretConnection();
.ConfigureFromActionConnection("MyProject.Migrations")
.ConfigureFromSecretConnection("MyProject.Migrations");
```

0 comments on commit 4c7d8d4

Please sign in to comment.