1+ using Microsoft . AspNetCore . Http ;
2+ using Microsoft . Extensions . Configuration ;
13using Microsoft . Extensions . DependencyInjection ;
24using Microsoft . Extensions . Logging ;
35using Xunit . DependencyInjection . Logging ;
@@ -8,19 +10,35 @@ class Startup
810{
911 public void ConfigureServices ( IServiceCollection services )
1012 {
13+ // 构建配置
14+ var configuration = new ConfigurationBuilder ( )
15+ . AddJsonFile ( "appsettings.json" , optional : true , reloadOnChange : true )
16+ . AddEnvironmentVariables ( )
17+ . Build ( ) ;
18+
19+ services . AddSingleton < IConfiguration > ( configuration ) ;
20+
21+ // 添加测试用的 HttpContextAccessor
22+ services . AddSingleton < IHttpContextAccessor , TestHttpContextAccessor > ( ) ;
23+
1124 services . AddRagflowSharp ( options =>
1225 {
13- // options.ApiKey = "ragflow-U3MTFkNGFjMmMyNjExZjA5NjUxMDI0Mm";
14- // options.BaseUrl = "http://localhost";
26+ // 从环境变量或配置文件中读取设置
27+ options . ApiKey = Environment . GetEnvironmentVariable ( "RAGFLOW_API_KEY" )
28+ ?? configuration [ "RAGFlowSharp:ApiKey" ]
29+ ?? throw new InvalidOperationException ( "RAGFLOW_API_KEY environment variable or RAGFlowSharp:ApiKey configuration is required" ) ;
30+
31+ options . BaseUrl = Environment . GetEnvironmentVariable ( "RAGFLOW_BASE_URL" )
32+ ?? configuration [ "RAGFlowSharp:BaseUrl" ]
33+ ?? "http://localhost:8000" ;
1534
16- options . ApiKey = "ragflow-U3MTFkNGFjMmMyNjExZjA5NjUxMDI0Mm" ;
17- options . BaseUrl = "http://localhost" ;
1835 options . EnableLogging = true ;
1936 } ) ;
2037
2138 services . AddLogging ( lb =>
2239 {
2340 lb . AddXunitOutput ( ) ;
2441 } ) ;
42+
2543 }
2644}
0 commit comments