私はStructureMap、v.2.5.3を使用していますが、デコレータパターンを実装するためにインタフェース上で実装を連鎖させることに問題があります。StructureMapとデコレータパターン
私はウィンザーに慣れています。ここでは、インターフェース実装のバリエーションを指定して名前付きインプットを送信することができます。別の(デフォルト)インプットに変換します。
これはデフォルトで、正常に動作します非飾られたバージョン:
ObjectFactory.Initialize(registry =>
{
registry.ForRequestedType<ICommentService()
.TheDefault.Is.OfConcreteType<CommentService>();
... }
これは私が呼び出したいこと、デコレータのCTORです:
public CommentAuditService(ICommentService commentService,
IAuditService auditService)
これは動作しますが、ありません装飾されたオブジェクトにアクセスできないようにしてください:
registry.ForRequestedType<ICommentService>()
.TheDefault.Is.OfConcreteType<CommentService>()
.EnrichWith(x => new CommentAuditService());
ループ:
registry.ForRequestedType<ICommentService>()
.TheDefault.Is.OfConcreteType<CommentService>()
.EnrichWith(x => new CommentAuditService(new CommentService(),
new AuditService()));
これまでにされて私には思える必要があり作品:
registry.ForRequestedType<ICommentService.()
.TheDefault.Is.OfConcreteType<CommentAuditService>()
.WithCtorArg("commentService")
.EqualTo(new CommentService());
それはCommentAuditService
の新しいインスタンスを作成するための無限ループにそれを送っしかし、誰もが持っています迅速な答え? (Castle.Windsorに切り替える以外、私は現時点で非常に近くにいる)
チケットがあります!ありがとうジョシュア – iammaz