[英]how to override value in appsettings.json file between 2 different projects using .NETCore
I have a C# class library project and I am using appsettings.json to read values.我有一个 C# class 库项目,我正在使用appsettings.json读取值。
I have one MS Test (unit test) project and I am maintaining another appsettings.json file我有一个 MS 测试(单元测试)项目,我正在维护另一个appsettings.json文件
appsettings.json file in C# Class library project: appsettings.json 文件在 C# Class 库项目中:
{
"name" : "jack"
}
appsettings.json file in MS Test project: MS 测试项目中的 appsettings.json 文件:
{
"name" : "Mike"
}
My requirement is when I run the unit test the value "name" in the appsettings.json file in the C# class library project needs to be replaced with appsettings.json file in the MS Test project. My requirement is when I run the unit test the value "name" in the appsettings.json file in the C# class library project needs to be replaced with appsettings.json file in the MS Test project.
You should be using dependency injection to access configuration settings in your lib's classes;您应该使用依赖注入来访问 lib 类中的配置设置; simply manually construct an instance of the configuration class with the test values you desire and pass it to the lib classes' constructors.
只需使用您想要的测试值手动构造配置 class 的实例,并将其传递给 lib 类的构造函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.