From b9ba57dbfa86587aa83e7f213f2d92582b300eeb Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 8 Nov 2026 17:58:49 +0330 Subject: [PATCH] last ... --- Configurations/XAppConfiguration.cs | 1 + DI/XDIHelperExtension.cs | 5 ++++ Extensions/DIExtensions.cs | 37 +++++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Configurations/XAppConfiguration.cs b/Configurations/XAppConfiguration.cs index b8b4c58..14202b8 100644 --- a/Configurations/XAppConfiguration.cs +++ b/Configurations/XAppConfiguration.cs @@ -7,6 +7,7 @@ namespace xCommons.Configurations { public partial class XAppConfiguration { public string Name { get; set; } public string Version { get; set; } + public string Environment { get; set; } public string XPoweredValue { get; set; } public IEnumerable AllowedOrigins { get; set; } public string WelcomeMessage { get; set; } diff --git a/DI/XDIHelperExtension.cs b/DI/XDIHelperExtension.cs index 4f1f6e0..d75d78b 100644 --- a/DI/XDIHelperExtension.cs +++ b/DI/XDIHelperExtension.cs @@ -14,6 +14,11 @@ public static partial class XDIHelperExtension services.AddSingleton(); } + /// + /// Register XCommons Module Service ... + /// + /// + /// public static void AddXCommons( this IServiceCollection services, IConfiguration configuration diff --git a/Extensions/DIExtensions.cs b/Extensions/DIExtensions.cs index 61868d0..0192ae5 100644 --- a/Extensions/DIExtensions.cs +++ b/Extensions/DIExtensions.cs @@ -37,11 +37,44 @@ namespace xCommons.Extensions /// /// /// - public static void AddXAppConfiguration(this IServiceCollection services, IConfiguration configuration) + /// + public static void AddXAppConfiguration( + this IServiceCollection services, + IConfiguration configuration, + string environment = null + ) { // var appConfiguration = configuration.GetXAppConfiguration(); - services.AddSingleton(appConfiguration); + appConfiguration.Environment = environment; + + // + services.AddSingleton(appConfiguration); + } + + /// + /// Add Environment name to XAppConfiguration ... + /// + /// + /// + public static void AddEnvironmentToXAppConfiguration( + this IApplicationBuilder app, + string environmentName + ) + { + // + // Setting Environment in App Confiuration ... + using (var scope = app.ApplicationServices.CreateScope()) + { + // + // Inject AppConfiguration ... + var appConfiguration = scope.ServiceProvider + .GetRequiredService(); + if (!appConfiguration.IsNull()) + { + appConfiguration.Environment = environmentName; + } + } } ///