23 lines
883 B
C#
23 lines
883 B
C#
using MySqlConnector;
|
|
|
|
namespace AVSCartonShipmentVerifier.Data;
|
|
|
|
public sealed class VerificationDbConnectionFactory(IConfiguration configuration) : IVerificationDbConnectionFactory
|
|
{
|
|
private readonly string _connectionString = ResolveVerificationDatabase(configuration);
|
|
|
|
public MySqlConnection CreateConnection() => new(_connectionString);
|
|
|
|
private static string ResolveVerificationDatabase(IConfiguration configuration)
|
|
{
|
|
var cs = configuration.GetConnectionString("VerificationDatabase");
|
|
if (!string.IsNullOrWhiteSpace(cs))
|
|
return cs;
|
|
|
|
throw new InvalidOperationException(
|
|
"Connection string 'VerificationDatabase' is not set. Add it via appsettings.Local.json (next to the executable), " +
|
|
"user secrets (Development), or the environment variable ConnectionStrings__VerificationDatabase.");
|
|
}
|
|
}
|
|
|