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

New decorator injectableAll #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

axotion
Copy link

@axotion axotion commented Jul 11, 2020

Description

Howdy!

I want to open discussion about PoC of injectableAll decorator. I guess it's still missing feature when we have injectAll and don't have any decorator to aggregate injectables under one token.

@injectableAll('tags')
class Foo {}
@injectableAll('tags')
class Bar {}
@injectable()
class FooBar {
    constructor(@injectAll('tags') private fooBars: any[]) {}
}

(eg. refer PR #40 )

I created working implementation in this PR, but it's still more PoC than actuall implementation for missing decorator, so let's discuss!

@ghost
Copy link

ghost commented Jul 11, 2020

CLA assistant check
All CLA requirements met.

@ryall
Copy link

ryall commented Jul 21, 2020

Not part of the project so just my comments. Looks useful, but I think the naming is a bit confusing. Maybe injectableTagged or injectableAs. Alternatively, maybe it's simpler to simply allow the parameter on injectable.

@visualkhh
Copy link

@injectable()
@registry([{token: 'Bar', useClass: Foo}])
class Foo implements Bar {}
@injectable()
@registry([{token: 'Bar', useClass: Baz}])
class Baz implements Bar {}

and

@registry([
     // registry is optional, all you need is to use the same token when registering
     {token: "Bar", useToken: Foo}, // can be any provider
     {token: "Bar", useToken: Baz}
 ])
 class MyRegistry {}
 const myBars = container.resolveAll<Bar>("Bar"); // myBars type is Bar[]

@seriouslag
Copy link

@injectable()
@registry([{token: 'Bar', useClass: Foo}])
class Foo implements Bar {}
@injectable()
@registry([{token: 'Bar', useClass: Baz}])
class Baz implements Bar {}

and

@registry([
     // registry is optional, all you need is to use the same token when registering
     {token: "Bar", useToken: Foo}, // can be any provider
     {token: "Bar", useToken: Baz}
 ])
 class MyRegistry {}
 const myBars = container.resolveAll<Bar>("Bar"); // myBars type is Bar[]

I wouldn't call this a workaround to the proposed PR. Hard coding each token to a symbol in a different location than where the tokens are defined isn't very helpful. Maybe I am misunderstanding but writing a class to bind the tokens isn't as helpful as what is proposed in this PR where we can do this spread out through the codebase.

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.

4 participants