使用元标记或吸气剂注入更好/更快/更轻?动作脚本 3 / 柔性

发布于 2024-10-03 02:24:11 字数 369 浏览 1 评论 0原文

我想知道哪一个更好/更快/更轻?

[Inject]
public var myInjection:MyInjection;

或者

[Inject]
public var injector:IInjector;

protected var _myInjection:MyInjection;

public function get myInjection():MyInjection{
    if(!_myInjection) _myInjection = injector.getInstance(MyInjection);
    return _myInjection;
}

I would like to know which one is better/faster/lighter?

[Inject]
public var myInjection:MyInjection;

OR

[Inject]
public var injector:IInjector;

protected var _myInjection:MyInjection;

public function get myInjection():MyInjection{
    if(!_myInjection) _myInjection = injector.getInstance(MyInjection);
    return _myInjection;
}

?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

强者自强 2024-10-10 02:24:11

那么第一个是合适的。第二个很奇怪。

您已经在几个问题中注入了 IInjector。在我构建的所有 Robotlegs 应用程序中,我从未需要注入注射器。我唯一需要这样做的时候是当我编写框架扩展/实用程序时。

well the first one is appropriate. The second is weird.

You've injected the IInjector in a couple of questions. In all of the robotlegs apps I've built I have never needed to inject the injector. The only time I've needed to do that is when I was writing framework extensions/utils.

意犹 2024-10-10 02:24:11

我感觉第一个更快。 SwiftSuspenders 为每个注入者保留注入点的缓存 - 第二种方法可能不会利用该缓存。

I have a feeling that the first is faster. SwiftSuspenders keeps a cache of injection points for each injectee - the second method would probably not take advantage of that caching.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文