Windsor のサービス オーバーライドを使用すると、より簡単で簡単な方法が得られます。
たとえば、次のようにリポジトリを登録します。
container.Register(Component.For<IProductsRepository>
.ImplementedBy<ProductsRepository>()
.Named("defaultProductsRepository"),
Component.For<IProductsRepository>
.ImplementedBy<SpecificProductsRepository>()
.Named("specificProductsRepository"));
これにより、デフォルトの実装が確実になりますProductsRepository。次に、特定のコントローラーに対して、次のようにサービス オーバーライドを追加します。
container.Register(Component.For<NewController>()
.ServiceOverrides(ServiceOverride
.ForKey("productsRepository")
.Eq("specificProductsRepository"));
ここでドキュメントを読むことができます。
編集:リポジトリを に登録する場合はAllTypes、次のように登録キーを調整できます。
container.Register(AllTypes.[how you used to].Configure(c => c.Named(GetKey(c)));
たとえば、GetKey次のようなものです。
public string GetKey(ComponentRegistration registration)
{
return registration.Implementation.Name;
}