问题
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