使用 swiftSuspenders/robotlegs 手动注入自定义类
在我的上下文中:
var parserManager:ParserManager = injector.instantiate(ParserManager);
parserManager.injector = injector;
injector.mapValue(ParserManager, parserManager);
在我的 parserManager(不扩展任何其他类)类中:
public var injector:IInjector;
parserManager 被注入到某些模型中。 有更好的方法吗?这太脏了..
in my context:
var parserManager:ParserManager = injector.instantiate(ParserManager);
parserManager.injector = injector;
injector.mapValue(ParserManager, parserManager);
in my parserManager(doesn't extend any other class) class:
public var injector:IInjector;
the parserManager is injected in some models.
Is there a better way of doing it? this is so dirty..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 ParserManager 中:
我有点怀疑将注入器注入到名称中带有 Manager 的类中,但这是我能想到的完成它的最干净的方法。
您应该记住,在映射管理器之后,如果您不立即需要它,那么它将在首次创建时使用注入器注入(通过注入到使用它的另一个类中)。 Robotlegs 会延迟创建实例。
in ParserManager:
I am a little suspect of injecting the injector into a class with Manager in its name, but that is about the cleanest way I can think of to get it done.
You should keep in mind that after the manager has been mapped, if you don't need it immediately then it will be injected with the injector when it is first created (by being injected in another class that uses it). Robotlegs creates instances lazily.