Asp.net core ASP.NET Core 3.1 Startup.cs在将类添加到服务集合之前如何初始化该类

Asp.net core ASP.NET Core 3.1 Startup.cs在将类添加到服务集合之前如何初始化该类,asp.net-core,dependency-injection,Asp.net Core,Dependency Injection,我有一个要求,在将类作为作用域添加到服务集合之前,我想设置一些属性 从配置中读取动态属性后,如何设置它 private void ConfigureServices(IServiceCollection serviceCollection) { // read values from config ??PaymentService.Environment="DEV";?? // plus some more dynamic values

我有一个要求,在将类作为作用域添加到服务集合之前,我想设置一些属性

从配置中读取动态属性后,如何设置它

private void ConfigureServices(IServiceCollection serviceCollection)
{
     // read values from config
     ??PaymentService.Environment="DEV";??
     // plus some more dynamic values

     serviceCollection.AddScoped<IPaymentService, PaymentService>();
}
private void配置服务(IServiceCollection服务集合)
{
//从配置中读取值
?PaymentService.Environment=“DEV”;??
//再加上一些动态值
serviceCollection.addScope();
}
或者,在将类添加到作用域并更新值之后,如何检索该类的实例?

尝试以下操作:

serviceCollection.AddScoped<IPaymentService, PaymentService>(sp => new PaymentService() { Environment = "DEV" });
servicecolection.AddScoped(sp=>newpaymentservice(){Environment=“DEV”});