-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
New (TS-friendly) design for DI registration and lookup #583
Comments
Seems good generally, but the RFCs changes would have to apply to all APIs that currently support
I'd also probably use |
Yep, I figured that would be the case! I'd be happy to nail down all of those pieces. (Should have mentioned in the initial writeup that I knew there were others besides the ones I mentioned.) With regard to Edit: Oh, and yes, |
RFC opened as #585! |
Multiple times recently, I've stumbled over the fact that the current DI registry system is this close to being able to be straightforwardly type-check-able for TS consumers… and the change that would be required would IMO make for a nicer API (and cleaner internals!—at least once through the deprecation cycle) than the current one.
The current API for registrations and lookups is:
Here,
fullName
is a string like'<bucket>:<itemName>'
—for example,'service:session'
.It would be extremely helpful for TypeScript consumers (but also, in my opinion, nicer for everyone) if the registration and lookup API were:
The resulting API usage would look like this for
lookup
(and similar forregister
:For our purposes within the TS community, this would allow us to actually guarantee—with only tiny changes to work we've already done—that when a user looks up a service by doing
getOwner(this).lookup('service', 'session')
would safely give them aSession
instance, and we could also type-check the string passed.Outside the TS community, I can say that I know the
'<bucket>:<name>'
pattern confused me early on, and that I simply find two separate arguments to be much clearer.I'm happy to write an RFC that proposes this. If I did, I would propose starting by adding the new design within the current implementation, deprecating the single-string version of
lookup
andregister
at the same time, and then removing the single-string version at 4.0.The text was updated successfully, but these errors were encountered: