我正在使用机器人腿,我有一堆 ServiceResponses 扩展了一个基类并依赖于 Parser,IParser。我需要连接特定于子类的解析器。这是一个例子:
ModuleConfigResponse 扩展了 SimpleServiceResponse 并实现了 IServiceResponse。
初始部分很容易在上下文中连接,这是一个示例:
injector.mapClass(IServiceResponse, ModuleConfigResponse);
injector.mapClass(IServiceResponse, SimpleServiceResponse, "roomconfig");
..etc
每个响应使用基类使用的解析器:
injector.mapValue(IParser, ModuleConfigParser, "moduleconfig");
injector.mapValue(IParser, RoomConfigParser, "roomconfig");
问题是如何将这些联系在一起。基类可以有:
[Inject]
public var parser : IParser
但我无法提前定义类型。我想知道在上下文中是否有一种很好的接线方式。目前,我决定通过在 ResponseFactory 中实例化响应来连接它,以便我在构造函数中手动传递解析器。
injector.mapValue(IParser, ModuleConfigParser, "moduleconfig");