@@ -0,0 +1,23 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Shared.Models.Settings;
|
||||
|
||||
namespace StartupHelpers;
|
||||
|
||||
public static class DatabaseExtensions
|
||||
{
|
||||
public static string GetConfiguredDbConnectionString(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var dbOptions = configuration
|
||||
.GetSection("Database")
|
||||
.Get<DatabaseSettings>()
|
||||
?? throw new InvalidOperationException("Database config missing");
|
||||
|
||||
return
|
||||
$"Server={dbOptions.Host},{dbOptions.Port};" +
|
||||
$"Database={dbOptions.Name};" +
|
||||
$"User Id={dbOptions.User};" +
|
||||
$"Password={dbOptions.Password};" +
|
||||
$"TrustServerCertificate={dbOptions.TrustServerCertificate};";
|
||||
}
|
||||
}
|
||||
@@ -21,4 +21,8 @@
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="10.1.7" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\shared-models\shared-models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user