Typhoon : Obtain a Typhoon-built instance of a class without depending on Typhoon

我们两清 提交于 2020-01-25 10:58:06

问题


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?


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/31487472/typhoon-obtain-a-typhoon-built-instance-of-a-class-without-depending-on-typhoo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!