Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple-injection #39

Closed
wants to merge 1 commit into from
Closed

Multiple-injection #39

wants to merge 1 commit into from

Conversation

ilyapuchka
Copy link
Collaborator

Resolves #14

@ilyapuchka ilyapuchka force-pushed the feature/multi-injection branch from 8c3d3b3 to 8dd1f0f Compare January 28, 2016 00:15
@ilyapuchka ilyapuchka force-pushed the feature/multi-injection branch from 8dd1f0f to e8fdda5 Compare January 28, 2016 20:11
* Thread safety reimplemented with support for recursive methods calls.
[#31](https://github.com/AliSoftware/Dip/pull/31), [@mwoollard](https://github.com/mwoollard)
* Multi-injection to resolve an array of all the instances registere for the protocol.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

registered

@AliSoftware
Copy link
Owner

Already said that in #14 but I'm really not sure this is worth adding.

I like having a library that doesn't become a huge do-it-all lib. Keeping the API simple is important to me, and adding convenience methods to do something that the user can really easily do on its own if really needed does not seem to go in that direction, but rather adds methods in the API for which the user might wonder why it's here (in the sense "that feature is so simple to do it on my own, why is there a dedicated method to do this, if there is a dedicated method does it means that this is in fact not as obvious as I think it is?" etc)

In your examples, it seems to me that using a simple map allows to achieve the exact same effect that this feature does:

enum Services: String {
  case GMail, Yahoo, Outlook
  let allValues: [Services] = [.GMail, .Yahoo, .Outlook]
}
container.register(tag: Services.GMail) { GmailService() as ThirdPartyEmailService }
container.register(tag: Services.Yahoo) { YahooService() as ThirdPartyEmailService }
container.register(tag: Services.Outlook) { OutlookService() as ThirdPartyEmailService }

let thirdPartyServices = Services.allValues.map { try! container.resolve(tag: $0) as ThirdPartyEmailService }

Then, exactly like in your example in the playground, if you realize later that you want to add a service, simply add it in the allValues property of the enum.

@ilyapuchka
Copy link
Collaborator Author

Sure, it can be done by user with ease. I'm ok with not including that feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants