I have a Castle Windsor container registration class as follows...
public class WindsorInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component.For<IConfigProvider>()
.ImplementedBy<ConfigProvider>()
.LifeStyle.Singleton);
container.Register(Component.For<IDbRepository>()
.ImplementedBy<DbRepository>()
.LifeStyle.Singleton
.DependsOn(Dependency.OnValue(
"connectionString",
// -- Somehow call GetConfig() on the IConfigProvider --
)));
}
}
The DbRepository needs a connection string to be passed in on object construction. However, that connection string is actually supplied by the IConfigProvider.
Is it possible to get Castle Windsor to somehow resolve the IConfigProvider at this point and call the GetConfig method?
Open to other options if this is not a good idea.
You could use
DynamicParameters
to accomplish this:From the documentation:
In other words, you'll retrieve the connection string just before the component is resolved.