台风:在不依赖台风的情况下获取由台风构建的类的实例 [英] Typhoon : Obtain a Typhoon-built instance of a class without depending on Typhoon

查看:105
本文介绍了台风:在不依赖台风的情况下获取由台风构建的类的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过Typhoon故事板集成,依赖注入所需的全部就是在要注入的类上使用自动注入宏或组装方法.

With Typhoon storyboard integration, all that is necessary for dependency injection is to use auto-injection macros or assembly methods on the class to be injected.

但是在其他地方,有必要请台风为我们建立一个实例.有没有一种方法可以让我的班级不必依赖台风来获取实例?

However elsewhere, its necessary to ask Typhoon to build an instance for us. Is there a way to obtain an instance, without having my class depend on Typhoon?

推荐答案

是的,本着依赖注入的精神,Typhoon的设计使其对于任何用户类而言都不必直接依赖Typhoon.

Yes, in the spirit of dependency injection, Typhoon is designed so that its not necessary for any user classes to have a direct dependency on Typhoon.

假设您希望在Typhoon应用程序中从ViewControllerA获取ViewControllerB的实例.为此,我们为ViewControllerA创建定义,以便注入程序集,然后要求程序集构建实例.这是显示在示例应用程序中

Let's say you wish to obtain an instance of ViewControllerB from ViewControllerA within a Typhoon application. To do this, we create our definition for ViewControllerA such that the assembly is injected, and then ask the assembly to build an instance. This is shown in the sample application and detailed in the user guide here.

如果希望将应用程序类与Typhoon完全分离,则下一步是简单地使用协议支持程序集,然后注入该协议.这样,您的应用程序所看到的只是一个类视图控制器A所需的提供者接口,以完成其工作. 这是有关如何执行此操作的教程.

The next step, if you wish to completely decouple your application classes from Typhoon, is to simply back your assemblies with a protocol, and inject that. In this way, all your application sees is a provider interface for the class view controller A needs in order to do its job. Here's a tutorial on how to do this.

这篇关于台风:在不依赖台风的情况下获取由台风构建的类的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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