Cocoa 的依赖注入框架? [英] Dependency injection framework for Cocoa?

查看:28
本文介绍了Cocoa 的依赖注入框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Interface Builder 可用于 Cocoa 应用程序中的基本依赖注入,但是当您不想在 NIB 文件中实例化对象时,有没有人知道更完整的 Objective-C/Cocoa 依赖注入框架?

Interface Builder can be used for basic dependency injection in a Cocoa app, but is anyone aware of more complete dependency injection frameworks for Objective-C/Cocoa for when you don't want to instantiate objects in a NIB file?

编辑

澄清一下,我承认 IB 可用于基本 DI,但我正在寻找具有更完整功能的框架,包括独立的生产和测试配置,沿着 Groovy 或 Springs 的路线.

To clarify, I recognize that IB can be used for basic DI, but I'm looking for a framework with more complete functionality, including separate production and testing configurations, along the lines of Groovy or Springs.

推荐答案

我想你会发现在像 Objective C、Ruby、Lisp 等后期绑定语言中你不需要它.就像 Jamis 所揭示的,当他试图构建 Needle 时,他走上了一条过于复杂的道路,这是一个 Ruby 的 DI 框架 - Net::SSH 重新访问.

I think you'll find that you don't need it in late-binding languages like Objective C, Ruby, Lisp and so on. Like Jamis' revelation that he was going down an overly complex path when he tried to build needle, a DI framework for Ruby- Net::SSH revisited.

这里有一些链接,希望能为您提供一些示例代码,以便在 Objective C 中执行类似的操作.通过类别,您可以在运行时从本质上更改任何类的行为.请参阅 Mac 开发者提示 – Objective-C:类别关于类别的 Cocoa API 文档.本质上,您不需要某个中心位置来请求可配置的执行 x 的事情",因为您可以直接实例化 TheThingThatDoesX,如果其他东西需要更改/挂钩到该行为,它可以使用类别.

Here are some links that will hopefully give you some sample code to do similar things in Objective C. With categories you can essentially change any class's behavior at runtime. See Mac Developer Tips – Objective-C: Categories and the Cocoa API docs on categories. Essentially you don't need some central place to ask for "the thing that does x" that is configurable, because you can just instantiate TheThingThatDoesX directly and if something else needs to change/hook into that behavior it can use categories.

这篇关于Cocoa 的依赖注入框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆