我的目标是动态地将AppSettings注入我的.NET应用程序,这些应用程序托管在Azure的App Service产品上。我有一些设置,例如我希望在名为public final RestClients {
private final ServiceLoader<RestClient> restClients = ServiceLoader.load(RestClient.class);
public RestClient getClient(RestClientSpec spec) throws NoClientFoundForSpecException {
for (RestClient client : restClients) {
if (/* client matches your specification */) {
return client;
}
}
throw new NoClientFoundForSpecException(spec);
}
}
的参数中定义的copy loop中注入key3
和key4
,该参数将适用于我的所有应用。
我正在尝试figure out the syntax注入一个名为appList
的{{1}}类型myAppSettings
的已定义参数。我看过微软关于using objects as parameters的文档,但它并不适合我的情况。
这是我的代码
azuredeploy.json
object
azuredeploy.parameters.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"aspName": { "value": "my-asp" },
"aspSkuName": { "value": "B1" },
"webAppNameHostnameSuffix": { "value": "myhost.com" },
"appList": { "value": [ "myapp1", "myapp2", "myapp3","myapp4"] }
"myAppSettings": {
"value": {
"key3": "value3",
"key4": "value4"
}
}
}
}
该行正在抛出错误
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"aspName": { "type": "string", "minLength": 1,"metadata": { "description": "Name of App Service Plan" } },
"aspSkuName": {"type": "string", "allowedValues": [ "F1", "D1", "B1", "B2", "B3", "S1", "S2", "S3", "P1", "P2", "P3", "P4" ] },
"appList": { "type": "array" },
"myAppSettings": { "type": "object" }
},
"variables": {},
"resources": [
{
"name": "[parameters('aspName')]",
"type": "Microsoft.Web/serverfarms",
"location": "[resourceGroup().location]",
"apiVersion": "2015-08-01",
"sku": { "name": "[parameters('aspSkuName')]" },
"tags": { "displayName": "asp1" },
"properties": {
"name": "[parameters('aspName')]",
"numberOfWorkers": 1
}
},
{
"name": "[concat(parameters('webAppAzureNamePrefix'), parameters('appList')[copyIndex()])]",
"copy": {
"name": "webAppCopy",
"count": "[length(parameters('appList'))]"
},
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"apiVersion": "2015-08-01",
"dependsOn": [ "[resourceId('Microsoft.Web/serverfarms', parameters('aspName'))]" ],
"tags": { "displayName": "webapp" },
"properties": {
"name": "[concat('some-prefix', parameters('appList')[copyIndex()])]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('aspName'))]"
},
"resources": [
{
"name": "appsettings",
"type": "config",
"apiVersion": "2015-08-01",
"dependsOn": [ "[resourceId('Microsoft.Web/sites', concat('some-prefix', parameters('appList')[copyIndex()]))]" ],
"tags": { "displayName": "appsettings" },
"properties": { [parameters('myAppSettings')] }
},
{
"name": "web",
"type": "config",
"apiVersion": "2015-08-01",
"dependsOn": [ "[resourceId('Microsoft.Web/sites', concat('some-prefix', parameters('appList')[copyIndex()]))]" ],
"tags": { "displayName": "web" },
"properties": { "alwaysOn": true }
}
]
}
],
"outputs": {}
}
错误消息
"properties": { [parameters('myAppSettings')] }
答案 0 :(得分:2)
"properties": "[parameters('myAppSettings')]"
如果变量\参数是一个对象而某些东西需要一个对象,则只需传递变量\ _参数。
阵列也一样。