2

I am trying to setup DI for multi-module workspace with Swinject. I have one ParentProject where I embed binary framework built from ChildProject (so ParentProject includes all public code from ChildProject).

My approach is to create one Assembly for each module, and assemble them together in ParentProject. The errors I am getting are really weird to me, take one for NSPersistentContainer:

Swinject: Resolution failed. Expected registration: { Service: NSPersistentContainer, Factory: Resolver -> NSPersistentContainer } Available registrations: { Service: NSPersistentContainer, Factory: Resolver -> NSPersistentContainer, ObjectScope: container }

Example of Assembly from ParentProject:

public class ParentProjectAssembly: Assembly { ... public func assemble(container: Container) { ... container.register(NSPersistentContainer.self) { _ in return self.persistentContainer }.inObjectScope(.container) ... } }

It doesn't really matter if I move this registration code to the ChildProjectAssembly or I have this registration in both of them, error is always the same. My assembler is just Assembler([ParentProjectAssembly(), ChildProjectAssembly()] in ParentProject's AppDelegate (for now). It seems that everything works fine, assemble(container:) method has the same container for all of the assemblies, some injections do work, but others have this error suggesting that I should register service without specifying objectScope at all? That isn't possible.

Help

0 Answers0