为不同的实现提供相同类型的不同配置?

Supplying different configurations of the same type to different implementations?

我有两个实现,每个实现都需要一组不同的配置数据相同类型:

public ConsumerA(Configuration config) : IConsumerA { ... }
public ConsumerB(Configuration config) : IConsumerB { ... }

在我的安装程序中,我让 Windsor 解析实现:

container.Register(
    Component.For<IConsumerA>().ImplementedBy<ConsumerA>().LifestyleTransient(),
    Component.For<IConsumerB>().ImplementedBy<ConsumerB>().LifestyleTransient()
);

如何让Windsor根据各自的实现解析配置?

我最后做的是命名配置并使用工厂,有点像这样:

Component.For<IConsumerA>().ImplementedBy<ConsumerA>()
    .DependsOn(Dependency.OnComponent(typeof(Configuration), "configurationA")).LifestyleTransient(),
Component.For<IConsumerB>().ImplementedBy<ConsumerB>()
    .DependsOn(Dependency.OnComponent(typeof(Configuration), "configurationB")).LifestyleTransient(),

Component.For<Configuration>().UsingFactoryMethod(
   k => k.Resolve<ConfigurationFetcher>()
       .GetConfigurationSection<ConfigurationSection>(ConfigurationSection.ConfigurationASectionName)
       .GetConfiguration()).Named("configurationA"),
Component.For<Configuration>().UsingFactoryMethod(
   k => k.Resolve<ConfigurationFetcher>()
       .GetConfigurationSection<ConfigurationSection>(ConfigurationSection.ConfigurationBSectionName)
       .GetConfiguration()).Named("configurationB"),