私は現在、それはdoesnのように、私はWithService.Selfを使用してい既存の城ウィンザー登録
Container.Register(AllTypes.FromAssemblyContaining<MyAssembly>()
.BasedOn(typeof(IRepository<>))
.WithService.Self().Configure(c => c.LifeStyle.Transient));
私の初期化シーケンスの1点で原料の束を登録してるにフォワード型を追加する方法自動的にAllInterfacesをピックアップするので、後でタイプをフォワードとして追加したいインターフェイスはまだ追加されていません。
既に登録されているコンポーネントの1つにタイプを追加したい場合はForwardedTypesプロパティのIntellisenseが.Forward(typof())を使用して提案します。
Container.Register(Component.For<IOtherInterface>()
.Forward(typeof(IOtherInterface))
.ImplementedBy<AlreadyRegisteredType>().LifeStyle.Transient);
これは可能ですか?
EDIT:
私はクシシュトフはので、私はテストプロジェクト(以下)を生成した作業を示唆したことのものを取得しようとしてきました。私はさまざまな組み合わせを試して、IMyInterfaceをMySecondTypeに転送するようにしましたが、コンポーネントタイプの初期登録後に2番目のステップとして完了すると、それを動作させることができません。私はおそらく暗いですが、私はConfigureForコマンドがどのように動作するのかを知りませんし、ドキュメンテーションはそのサブジェクト上で少しはスケッチではありません。
namespace TestProject1
{
public class MyType : IMyInterface
{
public virtual string MyProperty { get; set; }
}
public class MySecondType : IMyInterface
{
public virtual string MySecondProperty { get; set; }
}
public interface IMyInterface
{
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
//New Container
var container = new WindsorContainer();
//Register Types
container.Register(
AllTypes.FromAssemblyContaining<MyType>().BasedOn<IMyInterface>().WithService.Self().Configure(
c => c.LifeStyle.Transient));
//Other stuff happens here...
//Now Register our interface as a forward
container.Register(AllTypes.FromAssemblyContaining<IMyInterface>()
.BasedOn<IMyInterface>()
.WithService.Base()
.ConfigureFor<IMyInterface>(r => r.Forward<MySecondType>()).Configure(c => c.LifeStyle.Transient));
var typeA = new MySecondType();
var typeB = container.Resolve<IMyInterface>();
Assert.IsInstanceOfType(typeB.GetType(), typeA.GetType());
}
}
}
ソリューションは簡単だったので、それは、実際にエラーが "キー" 文句を言っていた...何もシンプルだったOK: Container.Register(Component.For() の.forward(typeof演算(IOtherInterface )) .Named( "IOtherInterface") .ImplementedBy ()。LifeStyle.Transient); キーの名前を変更するだけです。私はこれを答えとして掲示しますが、別の7時間はできません... ;-) –