c# - 城堡温莎流利的 API : How to set a component parameter value to a configured property

标签 c# castle-windsor fluent-interface

我刚刚开始使用 CaSTLe Windsor 的 Fluent 注册,无法弄清楚如何在注册时引用我在 XML 配置文件的属性部分中定义的属性。所以我有这段代码来注册一个组件。

RegisterComponent(componentId, Component.For<ConnectionConfig>()
            .ImplementedBy(typeof(ConnectionConfig))
            .Named(componentId)
            .LifeStyle.Singleton
            .Parameters(
                Parameter.ForKey("ConnectionId").Eq(connectionId),
                Parameter.ForKey("CommandTimeoutSeconds").Eq("#{ConnectionInfo.DefaultTimeout}")));

#{ConnectionInfo.DefaultTimeout} 是我在 XML 配置中定义的属性,它在 Fluent 注册之前加载到容器中,但这不起作用,在此代码中,传递给 Eq() 的参数被处理作为文字(尽管这适用于其他组件,即 ${My.Component} 会起作用)

有什么想法可以在通过新的 Fluent API 注册组件时从我的配置文件中引用属性吗?

谢谢

最佳答案

较新版本的 Windsor (3.x) 对此有内置支持:

Component.For<Foo>().DependsOn(Dependency.OnAppConfigValue("someValue"))

关于c# - 城堡温莎流利的 API : How to set a component parameter value to a configured property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/939659/

相关文章:

c# - 从 WCF 创建客户端查看 SOAP XML

c# - 温莎城堡 : How do I inject all implementations of interface into a ctor?

c# - 如何在 ASP.NET 中管理应用程序配置?

c# - 具有向后导航的流畅接口(interface)(方法链接)

entity-framework - 指定外键 Entity Framework 代码优先,Fluent Api

c# - 如何不包含正则表达式的一部分

c# - Visual Studio 2015 的 MVC 片段?

c# - 有没有办法指定在站点范围内使用哪个字符串比较?

.net - IWindsorInstaller和CaSTLe中的AbstractFacility之间的区别

c# - 返回未指定类型的泛型