/// <summary> /// Converts this instance of PostgreSQL configuration section into a PostgreSQL connection string. /// </summary> /// <param name="config">Configuration section to convert.</param> /// <returns>PostgreSQL connection string.</returns> public static string ToPostgresConnectionString(this TurretConfigPostgres config) { // check if config is null if (config == null) { throw new NullReferenceException(); } // build the connection string out of supplied parameters var csb = new NpgsqlConnectionStringBuilder { Host = config.Hostname, Port = config.Port, Database = config.Database, Username = config.Username, Password = config.Password, SslMode = config.UseEncryption ? SslMode.Require : SslMode.Disable, TrustServerCertificate = config.TrustServerCertificate }; return(csb.ConnectionString); }
/// <summary> /// Creates a new instance of the string provider service. /// </summary> /// <param name="cfg"></param> public ConnectionStringProvider(TurretConfigPostgres cfg) { this.Config = cfg; this.ConnectionString = new Lazy <string>(() => this.Config.ToPostgresConnectionString()); }