I'm using typhoon in a swift project, as far as i understand i have to map all injections explicitly in a TyphoonAssembly like this:
public dynamic func appDelegate() -> AnyObject {
return TyphoonDefinition.withClass(AppDelegate.self) {
(definition) in
definition.injectProperty("cityDao", with:self.coreComponents.cityDao())
definition.injectProperty("rootViewController", with:self.rootViewController())
}
}
this seems hard to manage, and very fragile (when refactoring).
I see that there is support for auto injection (matching by types) here: https://github.com/appsquickly/Typhoon/wiki/Auto-injection-(Objective-C) but this is for objetive c.
Does anyone know of a way i can wire up the injection without explicitly registering props with their name as string?
Thanks!
(Typhoon creator here).
Typhoon is a dynamic, introspective dependency injection container , and uses the Objective-C run-time. There are the following limitations, when it comes to Swift:
You can instruct Typhoon to auto-wire a property in Swift using the following:
public dynamic func appDelegate() -> AnyObject {
return TyphoonDefinition.withClass(AppDelegate.self) {
(definition) in
definition.injectProperty("cityDao")
definition.injectProperty("rootViewController")
}
}
. . and this will match by type, just as the auto-wiring Objective-C macros do. However this does not avoid specifying the name of the property to be injected. There is no other way to do this in Swift. :(
Its worth mentioning there are additional limitations when using Typhoon with Swift:
@objc
directive - don't support introspection, dynamic dispatch or dynamic method invocation. Typhoon only works with Cocoa classes. @objc
directive.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.