forked from microsoft/Generative-AI-for-beginners-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppConfigurationService.cs
More file actions
53 lines (44 loc) · 1.73 KB
/
Copy pathAppConfigurationService.cs
File metadata and controls
53 lines (44 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
namespace MAF_MultiAgents;
/// <summary>
/// Centralized configuration service for managing application settings.
/// Handles reading from environment variables and user secrets.
/// </summary>
class AppConfigurationService
{
private static readonly Lazy<AppConfigurationService> _instance = new(() => new AppConfigurationService());
private readonly IConfiguration _configuration;
private AppConfigurationService()
{
var builder = Host.CreateApplicationBuilder();
_configuration = builder.Configuration
.AddEnvironmentVariables()
.AddUserSecrets<Program>()
.Build();
}
/// <summary>
/// Gets the singleton instance of the configuration service.
/// </summary>
public static AppConfigurationService Instance => _instance.Value;
/// <summary>
/// Gets the deployment name for the AI model, defaults to "gpt-5-mini".
/// </summary>
public string DeploymentName => _configuration["AzureOpenAI:Deployment"] ?? "gpt-5-mini";
/// <summary>
/// Gets the Azure OpenAI endpoint URL.
/// </summary>
public string? AzureEndpoint => _configuration["AzureOpenAI:Endpoint"];
/// <summary>
/// Gets the API key for Azure services.
/// </summary>
public string? ApiKey => _configuration["AzureOpenAI:ApiKey"];
/// <summary>
/// Gets the Azure Foundry project endpoint URL.
/// </summary>
public string? AzureFoundryProjectEndpoint => _configuration["AZURE_FOUNDRY_PROJECT_ENDPOINT"];
/// <summary>
/// Checks if Azure API key is configured and valid.
/// </summary>
public bool HasValidApiKey => !string.IsNullOrEmpty(ApiKey);
}