Skip to content

Instantly share code, notes, and snippets.

@danielmackay
Created May 22, 2024 11:33
Show Gist options
  • Save danielmackay/f506940fbbd84fdac987da3981841e9b to your computer and use it in GitHub Desktop.
Save danielmackay/f506940fbbd84fdac987da3981841e9b to your computer and use it in GitHub Desktop.
ASP.NET Core - Connection String Configuration
public static class ConfigurationExtensions
{
public static string GetConnectionStringOrThrow(this IConfiguration configuration, string name)
{
var connectionString = configuration.GetConnectionString(name);
if (string.IsNullOrWhiteSpace(connectionString))
{
throw new InvalidOperationException($"Connection string '{name}' not found.");
}
return connectionString;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment