开发者

Castle.Windsor: passing a dependency through 2 typed factories

Types:

public interface IWidgetFactoryFactory { IWidgetFactory CreateFactory(); } 

public interface IWidgetFactory { FooWidget CreateFoo(Foo model); }

public class FooWidget(IContextualService service, Foo model) { }

Registration:

Component.For<IWidgetFactoryFactory>()
         .AsFactory(),

// the CustomFactoryComponentSelector is unnecessary for this discussion, just know 
// it's there
Component.For<IWidgetFactory>()
         .AsFactory(c => c.SelectedWith<CustomFactoryComponentSelector>()),

Question:

What I want is to be able to add a method to IWidgetFactoryFactory which would take an IContextualService:

IWidgetFactory CreateFactory(IContextualService service);

and then create the factory proxy such that when I call IWidgetFactory.CreateFoo it resolves the IContextualService dependency from that parameter passed via the new CreateFactory method.

Note that I will be creating and calling multiple IWidgetFactoryFactory.CreateFactory(IContextualService) in different contexts, and I want each IContextualService to reflect the context 开发者_JAVA技巧it is called in and passed from.

Are there any ideas on how could this be done?

Update: There is a related thread on Castle-Dev mailing list on this issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜