在我的項目中的這一點上,我使用Swinject(DI容器)。Swinject註冊UIViewController最佳實踐
我想知道如何註冊的ViewController,如果我有以下層次:
class RateAnswersBaseVC: UIViewController { }
class RateAnswersDoctorVC: RateAnswersBaseVC { }
class RateAnswersQualityVC: RateAnswersBaseVC { }
如何將他們的權利,註冊和使用?我在我使用的第一個選項的項目這一點兩個選項,但有一種感覺,我們應該使用第二個:)
// ------- 1 --------
container.register(RateAnswersDoctorVC.self) { r in
let vc: RateAnswersDoctorVC = RateAnswersDoctorVC()
self.configureBasicFields(with: vc, container: container, resolver: r)
return vc
}
container.register(RateAnswersQualityVC.self) { r in
let vc: RateAnswersQualityVC = RateAnswersQualityVC()
self.configureBasicFields(with: vc, container: container, resolver: r)
return vc
}
// ------- 2 --------
container.register(RateAnswersBaseVC.self, name: "doctor") { r in
let vc: RateAnswersDoctorVC = RateAnswersDoctorVC()
self.configureBasicFields(with: vc, container: container, resolver: r)
return vc
}
container.register(RateAnswersBaseVC.self, name: "quality") { r in
let vc: RateAnswersQualityVC = RateAnswersQualityVC()
self.configureBasicFields(with: vc, container: container, resolver: r)
return vc
}
如果你解釋爲什麼你使用一個或另一個我會很高興方法。
感謝您的答覆