【问题标题】:Can't config constructor with one parameter无法使用一个参数配置构造函数
【发布时间】:2016-08-02 08:58:05
【问题描述】:

我尝试配置 RedisManagerPool。 RedisManagerPool 有 3 个构造函数,但我无法使用一个字符串参数(主机)设置构造函数。 它是调用必须至少提供异常。

代码是否有效,在注释损坏的代码中。

var host = CloudConfigurationManager.GetSetting("Data.Redis.ConnectionString");
var list = new List<string>() {host};
//TODO: Can't setup constructor with host parameter. I don't the reason.
//For<IRedisClientsManager>()
//    .Add<RedisManagerPool>()
//    .Ctor<string>("host").Is(host);
For<IRedisClientsManager>()
.Add<RedisManagerPool>()
.Ctor<IEnumerable<string>>("hosts").Is(list);

【问题讨论】:

  • 试试.Is((IEnumerable&lt;string&gt;)list)

标签: c# ioc-container structuremap


【解决方案1】:

我认为你需要使用 Use 而不是 Add

For<IRedisClientsManager>()
.Use<RedisManagerPool>()
.Ctor<IEnumerable<string>>("hosts").Is(list);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-28
    • 1970-01-01
    • 2013-03-25
    • 1970-01-01
    • 2011-03-15
    • 2011-10-08
    相关资源
    最近更新 更多