fix: 移除所有IConfiguration依赖,完全从环境变量读取配置,解决编译错误
This commit is contained in:
parent
9be6521fd0
commit
658cfe90e1
@ -19,14 +19,13 @@ public class MarketDataService : IMarketDataService
|
||||
/// </summary>
|
||||
/// <param name="logger">日志记录器</param>
|
||||
/// <param name="httpClientFactory">HTTP 客户端工厂</param>
|
||||
public MarketDataService(ILogger<MarketDataService> logger, IHttpClientFactory httpClientFactory, IConfiguration configuration)
|
||||
public MarketDataService(ILogger<MarketDataService> logger, IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_logger = logger;
|
||||
_httpClient = httpClientFactory.CreateClient();
|
||||
// 优先从环境变量读取 Tiingo API Key
|
||||
// 完全从环境变量读取 Tiingo API Key
|
||||
_tiingoApiKey = Environment.GetEnvironmentVariable("Tiingo__ApiKey")
|
||||
?? Environment.GetEnvironmentVariable("TIINGO_API_KEY")
|
||||
?? configuration["Tiingo:ApiKey"]
|
||||
?? "bd00fee76d3012b047473078904001b33322cb46";
|
||||
_httpClient.DefaultRequestHeaders.Add("Authorization", $"Token {_tiingoApiKey}");
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
@ -12,19 +11,16 @@ public class JwtService
|
||||
private readonly string _issuer;
|
||||
private readonly string _audience;
|
||||
|
||||
public JwtService(IConfiguration configuration)
|
||||
public JwtService()
|
||||
{
|
||||
// 优先从环境变量读取
|
||||
// 完全从环境变量读取
|
||||
_secretKey = Environment.GetEnvironmentVariable("Jwt__SecretKey")
|
||||
?? configuration["Jwt:SecretKey"]
|
||||
?? "your-strong-secret-key-here-2026";
|
||||
|
||||
_issuer = Environment.GetEnvironmentVariable("Jwt__Issuer")
|
||||
?? configuration["Jwt:Issuer"]
|
||||
?? "AssetManager";
|
||||
|
||||
_audience = Environment.GetEnvironmentVariable("Jwt__Audience")
|
||||
?? configuration["Jwt:Audience"]
|
||||
?? "AssetManager";
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace AssetManager.Services.Services;
|
||||
|
||||
@ -11,16 +10,14 @@ public class WechatService
|
||||
private readonly string _appId;
|
||||
private readonly string _appSecret;
|
||||
|
||||
public WechatService(HttpClient httpClient, IConfiguration configuration)
|
||||
public WechatService(HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
// 优先从环境变量读取
|
||||
// 完全从环境变量读取
|
||||
_appId = Environment.GetEnvironmentVariable("Wechat__AppId")
|
||||
?? configuration["Wechat:AppId"]
|
||||
?? "wx245f0f3ebcfcf5a7";
|
||||
|
||||
_appSecret = Environment.GetEnvironmentVariable("Wechat__AppSecret")
|
||||
?? configuration["Wechat:AppSecret"]
|
||||
?? "809c740129bc8b434177ce12ef292dd0";
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user