我正在使用Autofac JSON文件为我的项目中的相同接口注册两个类。在AUTOFAC中为同一接口使用不同的JSON配置文件
如果我做这样的事情:
JSON配置文件1:
{
"components": [
{
"type": "Services.FirstProvider, Services",
"services": [
{
"type": "Services.IHotelProvider, Services"
}
],
"parameters": {
"username": "<user>",
"password": "<pwd>"
}
}
]
}
JSON配置文件2:
{
"components": [
{
"type": "Services.SecondProvider, Services",
"services": [
{
"type": "Services.IHotelProvider, Services"
}
],
"parameters": {
"key": "<key>",
}
}
]
}
和注册:
config.AddJsonFile("First/FirstProviderConfig.json");
config.AddJsonFile("Second/SecondProviderConfig.json");
我看到只有SecondProvider
已被注册。并且切换注册:
config.AddJsonFile("Second/SecondProviderConfig.json");
config.AddJsonFile("First/FirstProviderConfig.json");
只有FirstProvider
已经注册。
如果我尝试在同一文件中注册它们:
{
"components": [
{
"type": "Services.FirstProvider, Services",
"services": [
{
"type": "Services.IHotelProvider, Services"
}
],
"parameters": {
"username": "<user>",
"password": "<pwd>"
}
},
{
"type": "Services.SecondProvider, Services",
"services": [
{
"type": "Services.IHotelProvider, Services"
}
],
"parameters": {
"key": "<key>"
}
}
]
}
它的工作原理。
我需要分离文件来配置它们。我想念什么?
有没有简单的方法来覆盖第一个JSON的一部分与第二个? (授予密钥匹配) – marsop