SwiftのDIコンテナは何がデファクト?使い所は?
from iOS開発わからないことリスト
使わないのが普通らしい(?)
https://twitter.com/the_uhooi/status/1239561673138036736
Dip
Swinject
多分一番スターが多い
Pure Swift
使い方を見ると、Service locatorだ
Typhoon
Objective-C時代からある
Cleanse
Swinjectより設計の筋が良さそう
深く見ていないので断定は不能
https://github.com/square/Cleanse
Square
Cleanse is a dependency injection framework for Swift. It is designed from the ground-up with developer experience in mind. It takes inspiration from both Dagger and Guice.
Root componentがあり、依存物をもつ形式
Root componentにはhow we construct every object/dependency in our app.の手続きを書く
configureRootはBindingReceipt<RootViewController>を返す
RootViewControllerクラスを作成してBinderに食わせる
サンプルがAppDelegate。これはSwitfUI以前のUIKit App Delegate形式のもの
https://dev.classmethod.jp/articles/xcode12_change_appdelegate/
Needle
https://github.com/uber/needle
Unlike other DI frameworks, such as Cleanse, Swinject, Needle encourages hierarchical DI structure and utilizes code generation to ensure compile-time safety.
This allows us to develop our apps and make code changes with confidence. If it compiles, it works.
2021-02-24 こちらもSwiftUIのサンプルはない
componentを使うことでバケツリレーを回避できる
https://medium.com/@yuyaHorita/ios-dependency-injection-by-needle-286ebadd2858
参考
2016 https://speakerdeck.com/yonekawa/iosapurifalseshe-ji-todependency-injection?slide=19