Created
May 22, 2024 11:33
-
-
Save danielmackay/f506940fbbd84fdac987da3981841e9b to your computer and use it in GitHub Desktop.
ASP.NET Core - Connection String Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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