gpt4 book ai didi

json - 具有 KeyFilter 属性的构造函数的 Autofac 配置

转载 作者:行者123 更新时间:2023-12-01 15:11:13 25 4
gpt4 key购买 nike

我正在尝试使用 Autofac 配置来创建服务对象。

public class Service : IService
{
public Service([KeyFilter("eod")]ISimpleMongoClient eodClient,
[KeyFilter("live")]ISimpleMongoClient liveClient
) : base(config)
{
_eodClient = eodClient;
_liveClient = liveClient;
}
}

public class SimpleMongoClient : ISimpleMongoClient
{
public SimpleMongoClient(string connectionString, string database)
{
IMongoClient client = new MongoClient(connectionString);
MongoDatabase = client.GetDatabase(database);
}
}

以下配置无法正确解析 ISimpleMongoClient 参数。我还缺少什么?

{
"components": [
{
"type": "Service, TestProject",
"services": [
{
"type": "IService, TestProject"
}
],
"instanceScope": "single-instance"
},
{
"type": "SimpleMongoClient, TestProject",
"services": [
{
"type": "ISimpleMongoClient, TestProject",
"key": "eod"
}
],
"parameters": {
"connectionString": "mongodb://localhost:27017/?readPreference=primary",
"database": "eod"
},
"instanceScope": "single-instance"
},
{
"type": "SimpleMongoClient, TestProject",
"services": [
{
"type": "ISimpleMongoClient, TestProject",
"key": "live"
}
],
"parameters": {
"connectionString": "mongodb://localhost:27017/?readPreference=primary",
"database": "live"
},
"instanceScope": "single-instance"
}
]
}

最佳答案

要使用 KeyFilter 属性,您需要注册进行过滤的东西 with the WithAttributeFiltering()扩大。你不能通过配置来做到这一点。

关于json - 具有 KeyFilter 属性的构造函数的 Autofac 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43636554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com