Closed vermont42 closed 4 years ago
AFAIK there is nothing special about SwinjectAutoregistration with regard to the access modifiers. If .init
is private, you cannot reference it from other source file - shouldn't matter in what context.
What puzzles me though, is that vanilla register
works 🤔
Is your injection code in the same sourcefile as the definition of RealGameCenter.init
? Could it be that RealGameCenter
has more that one init
? Can you reproduce this behavior in isolated example?
Thanks, @jakubvano.
Looking at the code now, I see that I had to comment out the line making RealGameCenter
's initializer private
, even for vanilla register
. My observation was incorrect.
Makes sense that a private
initializer would be problematic for Swinject.
In my conference talk and blog post, in the section on Swinject, I plan to mention, as a positive of Swinject, the help that you and other Swinject contributors provided.
Am I correct that, when I use
SwinjectAutoregistration
, no component initializer may be private?In my app, I have a service/protocol,
GameCenterable
, with two components that implement that protocol,RealGameCenter
andTestGameCenter
.RealGameCenter
has aprivate
initializer, which takes no arguments.TestGameCenter
has aninternal
initializer which takes aBool
argument,isAuthenticated
. For context, I show in the snippets below registration and use ofTestGameCenter
andRealGameCenter
. To make the latter work, I had to change the initializer ofRealGameCenter
fromprivate
tointernal
.Vanilla
Swinject
does not have this limitation, but I would prefer to useSwinjectAutoregistration
so I don't getOptional
s from the container.