using System; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace GB5Shared.Deployment { /// /// Registers the GB5 deployment-tier abstraction. Call in Program.cs: /// builder.Services.AddGB5Environment(builder.Configuration); /// Bind the "GB5" section from appsettings.json or environment variables /// (e.g. GB5__Environment=Dev|QC|Live) — there is no safe default in production, /// so an unconfigured tier fails fast at boot rather than silently resolving as Dev. /// public static class GB5EnvironmentServiceExtensions { public static IServiceCollection AddGB5Environment(this IServiceCollection services, IConfiguration configuration) { var section = configuration.GetSection(GB5EnvironmentOptions.SectionName); if (!section.Exists() || string.IsNullOrWhiteSpace(section["Environment"])) throw new InvalidOperationException( $"{GB5EnvironmentOptions.SectionName}:Environment must be set to Dev, QC, or Live."); if (!Enum.TryParse(section["Environment"], ignoreCase: true, out _)) throw new InvalidOperationException( $"{GB5EnvironmentOptions.SectionName}:Environment value '{section["Environment"]}' is not a valid GB5Tier (Dev, QC, Live)."); services.Configure(section); services.AddSingleton(); return services; } } }