-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inject dependancies of common parent ViewController #123
Comments
Assuming that common dependencies are injected as properties, you might be able to do it by implementing a custom container behavior, something along the lines of final class ParentViewControllerBehavior: Behavior {
func container<Type, Service>(
_ container: Container,
didRegisterType type: Type.Type,
toService entry: ServiceEntry<Service>,
withName name: String?
) {
guard type is ParentViewController.Type else { return }
entry.initCompleted { resolver, vc in
(vc as! ParentViewController).commonDependency = resolver.resolve(Any.self)
}
}
}
container.addBehavior(ParentControllerBehavior())
container.register(ChildViewController.self) { /* only need to inject specific dependencies */ } This basically checks every registration if the type inherits from |
@jakubvano Sorry for this late question. I tried above code for injecting some dependencies into my BaseViewController that is inherited by ViewControllers.
|
I think I figured out by my self. The code worked perfectly below
|
All of my ViewControllers have a common parent, lets say P. Is there a way to inject the parameters for this common parent whitout having to do this in each individual chiald view controller ?
The text was updated successfully, but these errors were encountered: