I am working on a private pod and currently I have some difficulty using Typhoon to inject property into the bootstrap class.
My class:
public class MyLibrary: NSObject {
var dependency: MyDependencyProtocol?
}
My assembly:
open class MyLibraryAssembly: TyphoonAssembly {
open dynamic func lib() -> Any
{
return TyphoonDefinition.withClass(MyLibrary.self) { (definition) in
definition?.injectProperty(#selector(getter: MyLibrary.dependency), with: self.dependency())
definition?.scope = .singleton
}
}
}
However, the consumer app will use var lib = MyLibrary() to initialise the object rather than using dependency injection. How do I inject dependency into the MyLibrary class when the init is called?
It might be better to define a class method in your
MyLibraryclass to return a build instance of yourMyLibraryclass. This method would:Example:
MyLibrary.instance()orMyLibrary.instanceWithConfig(someConfig).