如何从Swinject中的其他模块中解析
使用Tuist模块化了项目。我在数据模块和域模块上制作了RepositorityAssembly和UseCaseSembly。汇编器位于InjectManager中,并在App模块中的AppDelegate中运行。
// InjectManager.swift
public struct InjectManager {
public static func inject(container: Container) -> Assembler {
return Assembler([
RepositoryAssembly(),
UseCaseAssembly()
], container: container)
}
}
...
private var assembler: Assembler!
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
assembler = InjectManager.inject(container: InjectContainer.container)
return true
}
...
另外,在执行indetccontainer.container.container.solve中的resolve时,显示以下错误。
Swinject: Resolution failed. Expected registration:
{ Service: FetchRankingListUseCase, Factory: Resolver -> FetchRankingListUseCase }
Available registrations:
MainFeature/MainInteractor.swift:41: Fatal error: Unexpectedly found nil while unwrapping an Optional value
2022-04-26 23:36:21.127977+0900 GRIG[5952:4943332] MainFeature/MainInteractor.swift:41: Fatal error: Unexpectedly found nil while unwrapping an Optional value
当我打印InjectContainer.container时,
[
{ Service: FetchRankingListUseCase, Factory: Resolver -> FetchRankingListUseCase, ObjectScope: graph },
{ Service: GRIGRepository, Factory: Resolver -> GRIGRepository, ObjectScope: graph }
]
为什么会出现此错误?你能告诉我如何解决吗?
Modularized the project using Tuist. I made RepositoryAssembly and UseCaseAssembly on the Data module and Domain module. Assembler is located in InjectManager and runs in AppDelegate in the App module.
// InjectManager.swift
public struct InjectManager {
public static func inject(container: Container) -> Assembler {
return Assembler([
RepositoryAssembly(),
UseCaseAssembly()
], container: container)
}
}
...
private var assembler: Assembler!
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
assembler = InjectManager.inject(container: InjectContainer.container)
return true
}
...
Also, when performing InjetcContainer.container.resolve in MainFeature module, the following error is displayed.
Swinject: Resolution failed. Expected registration:
{ Service: FetchRankingListUseCase, Factory: Resolver -> FetchRankingListUseCase }
Available registrations:
MainFeature/MainInteractor.swift:41: Fatal error: Unexpectedly found nil while unwrapping an Optional value
2022-04-26 23:36:21.127977+0900 GRIG[5952:4943332] MainFeature/MainInteractor.swift:41: Fatal error: Unexpectedly found nil while unwrapping an Optional value
When I print the InjectContainer.container,
[
{ Service: FetchRankingListUseCase, Factory: Resolver -> FetchRankingListUseCase, ObjectScope: graph },
{ Service: GRIGRepository, Factory: Resolver -> GRIGRepository, ObjectScope: graph }
]
Why is this error coming out? Could you tell me how to solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论