2016-09-06 10 views
0

私は、各構成データの異なるセットを必要とする2つの実装を持っている同じタイプの:どのように私ができる同じタイプの異なる設定を異なる実装に提供していますか?

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

:私のインストーラで

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

、私はウィンザーの実装を解決する必要がありWindsorにそれぞれの実装に基づいて設定を解決するよう依頼しますか?

答えて

0

私は、ソートのようなので、設定を命名し、工場を使用していたやってしまった何を:

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"), 
関連する問題