2
votes

I am just getting started with the Fluent registration for Castle Windsor and cant figure out how I can reference properties I have defined in the properties section of my XML configuration file when registering. So I have this code to register a component.

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

The #{ConnectionInfo.DefaultTimeout} is a property I have defined in the XML config which is loaded into the container prior to the Fluent registrations, but this does not work, in this code the parameter passed to Eq() is treated as a literal (although this works for other components i.e. ${My.Component} would work)

Any ideas how I can reference properties from my configuration file while registering components through the new Fluent API?

Thanks

1

1 Answers

1
votes

More recent versions of Windsor (3.x) have a built-in support for this:

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