それはまさにそれを行う方法です。ドキュメントの「 Type Forwarding 」を参照してください。IHomeViewModel または IPageViewModel を介してアクセスできる 1 つの論理コンポーネントを登録します。次のテストに合格します。
public interface IHomeViewModel {}
public interface IPageViewModel {}
public class HomeViewModel: IHomeViewModel, IPageViewModel {}
[Test]
public void Forward() {
var container = new WindsorContainer();
container.Register(Component.For(new[] {typeof (IHomeViewModel), typeof (IPageViewModel)})
.ImplementedBy(typeof(HomeViewModel)).Named("IHomeViewModel").LifeStyle.Singleton);
Assert.AreSame(container.Resolve<IHomeViewModel>(), container.Resolve<IPageViewModel>());
}
ところで、シングルトンがデフォルトであるため、これらすべての代わりにジェネリックを使用しtypeof
、ライフスタイル宣言を削除することもできます。
container.Register(Component.For<IHomeViewModel, IPageViewModel>()
.ImplementedBy<HomeViewModel>());