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

Allow multiple tokens for the same value #65

Open
dmeehan1968 opened this issue Jul 25, 2023 · 0 comments
Open

Allow multiple tokens for the same value #65

dmeehan1968 opened this issue Jul 25, 2023 · 0 comments

Comments

@dmeehan1968
Copy link

It would be useful if the provide... functions would accept multiple tokens. This would be useful for describing interfaces that are implemented in an aggregate concretion, for example:

interface GetThing { get(id: string) : Thing }
interface PutThing { put(thing: Thing): void }

class ThingRepository implements GetThing, PutThing {
  get(id:string) { return 'thing' }
  put(thing: Thing) { }
}

const injector = createInjector().provideClass(['GetThing','PutThing', 'ThingRepository'], ThingRepository)

In this way, consumers can specify the interface they want, and get a concretion which provides that, even if it provides other things we don't care about.

At present we can specify multiple provide... calls, but in this case, the instance/value will be created for each token specified by a consumer, where we might actually intended to have a singleton or transient scope. Whilst it would be possible to provide a factory that deals with this, its somewhat obtuse and repetitive if we want to use the pattern extensively.

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

No branches or pull requests

1 participant