1

I've created a super simple protocol:

protocol IndependentProtocol {}

and service:

class IndependentService: IndependentProtocol {}

and the following Swinject registration works:

defaultContainer.register( IndependentProtocol.self )
{ 
    _ in IndependentService()
}

but the following one does not:

defaultContainer.register( IndependentProtocol.self )
{ 
    _ in IndependentService()
}.inObjectScope( .Container )

error given is:

Ambiguous reference to member 'register(_:name:factory:)'

and interestingly, the following works (ie: services with parameters can be registered in .container scope):

    defaultContainer.register( AnotherProtocol.self )
    {
        r in AnotherService(
            signals: r.resolve( AnotherService.self )!
        )
    }.inObjectScope( .container )

I have read this similar question, which did not help: Swinject - Ambiguous reference to member

Thank you all in advance.

Community
  • 1
  • 1
Joseph Beuys' Mum
  • 2,395
  • 2
  • 24
  • 50

1 Answers1

5

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)
Mark
  • 7,167
  • 4
  • 44
  • 68