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
Swiftで相互依存のオブジェクト生成に失敗する #3
Comments
BTKInjectorとしての支援は特にないので、単純にFactory用のプロトコルを定義して、Providerとして注入します。最初はFactoryとProviderを分けて考えていたのですが、どのみちFactory用のプロトコルは使用者が書かないといけないので、Providerだけのサポートとしました。Simple is the best :-) あと、Swiftの件、ありがとうございます。 |
ありがとうございます 👍 ちなみに、Swiftは以下のテストコードは動きました。 Objective-Cのテストも、 try-catchじゃなくて class BTKInjectorDuckTypingTests: XCTestCase {
func testWithDuckTyping() {
let injector = BTKGlobalInjector.injectorWithBlock { mInjector in
mInjector.bindProtocol(BTKTestProtocol4.self, forceConform: true) { injector in
return BTKTestProtocol1Impl()
}
}
let proxy = injector.proxyFor(BTKTestProtocol4.self) as BTKTestProtocol1
XCTAssertTrue(proxy.isKindOfClass(BTKTestProtocol1Impl.self))
let obj = proxy as BTKTestProtocol1Impl
XCTAssertEqual(obj.test1(), "test1")
}
} |
やはり、想定より早いタイミングでプロトコルチェックが走るね。 BTKInjectorProxyLazyで下記のようにprotocolチェックを飛ばすのがいいかな。
いかがでしょう? |
早速ありがとうございます。 - (BOOL)conformsToProtocol:(Protocol *)aProtocol
{
return _provider.targetProtocol == aProtocol;
} |
あと、逆に一つ質問があるのですが、ライブラリの方にブリッジヘッダを入れておいたほうがSwiftな人には便利なんでしょうか? |
ブリッジヘッダには自前で入れる習慣なので、無くて良いかもです。 プルリクは明日やってみますヽ(・ω・`) |
#4 でプルリクエスト投げました。(プルリクエストのお作法通りか少し自信ないです。 「ライブラリの方にブリッジヘッダを入れる」など、Swiftならではの工夫などは特に無かったです。 |
Swiftで使おうとしたら、以下の現象が起こってしまいました。
あと、別途Issue立てるか迷ったのですが、現在Factoryクラスが無いようですが、常に新しいインスタンスを返してほしい時はどういう使い方を想定していますか?
Objective-C - BTKInjector : DI Containerを作ってみた。 - Qiita
相互依存の問題はありましたが、Swiftからも使い易い感じで良いですね!
The text was updated successfully, but these errors were encountered: