Swinject / SwinjectAutoregistration

Swinject extension to automatically register your services
MIT License
249 stars 45 forks source link

Auto-register on resolve #58

Closed Evertt closed 3 years ago

Evertt commented 4 years ago

To be completely honest I haven't used this library yet. I was just reading the documentation and then I saw this line of code:

container.autoregister(MyService.self, initializer: MyService.init)

And then I thought, well in that particular case why would you need to register the service at all? I come from a PHP background and in the Laravel framework the container has this feature that you can ask it to resolve a concrete class that you haven't even registered in it, because it can just auto-resolve all the bindings on the fly.

Wouldn't that be possible here too?

tkohout commented 3 years ago

the registration has to happen somewhere. This is limitation of Swinject rather than SwinjectAutoregistration.

And I don't think you can do this in Swift anyway - how would Swinject know which init to use?