Swinject service class without parameters failing to register in .container scope with Swift 3.0: why?
As Jakub has commented, the issue lies with your capitalization of .Container
. Update the registration to the following:
defaultContainer.register(IndependentProtocol.self, factory: { _ in
IndependentService()
}).inObjectScope(.container)
Swinject - Ambiguous reference to member
I faced the same issue and i think compiler could be a bit more verbose in this case.
Anyway, my problem was on my side, not in Swinject
Check the following:
NetworkModeling
andNetwork
are visible in scope of your registration (they arepublic
, orinternal
in the same module. remember, that swift3 introducedfileprivate
and many other specifiers, so make sure your identifiers are visible to registeting codeMake sure that
Network
conforms toNetworkModeling
. Being unable to see inheritance, swift compiler raises error about ambigous types for Swinject factory
Hope, this helps
Dependency injection inconsistency in differing ViewControllers in Swinject, post Swift 3.0 update: why?
It turns out this is a bug, detailed here: https://github.com/Swinject/Swinject/issues/177. A fix is currently being worked on. I will report back once I know more.
UPDATE
This is apparently fixed.
Why is Swinject model class registered without .inObjectScope( .Container ) producing a singleton?
Default scope for services is .Graph
. From documentation:
With ObjectScope.Graph, an instance is always created, as in ObjectScope.None, if you directly call resolve method of a container, but instances resolved in factory closures are shared during the resolution of the root instance to construct the object graph.
If you want a unique instance to be created for each reference even during object graph resolution, you should use object scope .None
, i.e.
defaultContainer.register(Stopwatch.self) { resolver in
Stopwatch(signals: resolver.resolve(SignalsService.self)!)
}.inObjectScope(.None)
Related Topics
How to Grab The Parent Object from a Subview
Can't Set @Ibinspectable Computed Property in UIview
Xcode9/Scenekit - .Dae File Not Loading into Scnscene - Returns Nil
No Trailing Closures Support for Methods with Default Parameter Values
How to Horizontally Center Content of Horizontal Scrollview
How to Delay a Return-Statement in Swift
How to Detect Day Change in Swift
Swift Initialization Rule Confusion
How to Convert an Array to List in Realm
How to Calculate The Camera Position from Vuforia Gl Matrix
Dynamic Links Firebase Function Not Being Called at All Xcode 12
Swift 3 Custom Extension of Ns Measurement? Ex. Sheeps to Goats
Pass Custom Parameter to UIbutton #Selector Swift 3
Compiler Segmentation Fault While Using Set in Swift
On Demand Resources "0 Asset Packs"
Compiling for iOS 10.3, But Module 'swiftuicharts' Has a Minimum Deployment Target of iOS 13.0