mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-07-16 17:47:22 +00:00
add xmldoc comments
This commit is contained in:
@@ -4,6 +4,11 @@ using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Infrastructure.Repository.Sql;
|
||||
|
||||
/// <summary>
|
||||
/// Default <see cref="ISqlConnectionFactory"/> implementation that creates SQL Server connections,
|
||||
/// resolving the connection string from environment variables or application configuration.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The application configuration, used as a fallback source for the connection string.</param>
|
||||
public class DefaultSqlConnectionFactory(IConfiguration configuration)
|
||||
: ISqlConnectionFactory
|
||||
{
|
||||
@@ -11,6 +16,17 @@ public class DefaultSqlConnectionFactory(IConfiguration configuration)
|
||||
configuration
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the SQL Server connection string, preferring (in order): the <c>DB_CONNECTION_STRING</c>
|
||||
/// environment variable, a connection string built from individual <c>DB_*</c> environment variables
|
||||
/// via <see cref="SqlConnectionStringHelper.BuildConnectionString"/>, and finally the <c>"Default"</c>
|
||||
/// connection string from <paramref name="configuration"/>.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The application configuration to fall back to.</param>
|
||||
/// <returns>The resolved SQL Server connection string.</returns>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// Thrown when no connection string can be resolved from any of the supported sources.
|
||||
/// </exception>
|
||||
private static string GetConnectionString(IConfiguration configuration)
|
||||
{
|
||||
// Check for full connection string first
|
||||
@@ -42,6 +58,10 @@ public class DefaultSqlConnectionFactory(IConfiguration configuration)
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new, unopened <see cref="SqlConnection"/> using the resolved connection string.
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="SqlConnection"/> instance.</returns>
|
||||
public DbConnection CreateConnection()
|
||||
{
|
||||
return new SqlConnection(_connectionString);
|
||||
|
||||
@@ -2,7 +2,14 @@ using System.Data.Common;
|
||||
|
||||
namespace Infrastructure.Repository.Sql;
|
||||
|
||||
/// <summary>
|
||||
/// Factory for creating database connections used by repositories.
|
||||
/// </summary>
|
||||
public interface ISqlConnectionFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new, unopened database connection.
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="DbConnection"/> instance.</returns>
|
||||
DbConnection CreateConnection();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace Infrastructure.Repository.Sql;
|
||||
|
||||
/// <summary>
|
||||
/// Helper for building SQL Server connection strings from environment variables.
|
||||
/// </summary>
|
||||
public static class SqlConnectionStringHelper
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user