joist icon indicating copy to clipboard operation
joist copied to clipboard

Create a non constructable ProviderToken

Open deebloo opened this issue 9 months ago • 3 comments

At the moment we assume that all tokens are constructable. This works for 99% of use cases. There are often times where you might want to inject someone other than an object or want to require a specific definition.

An 'InjectionToken<T>' will define a specific symbol to be used in the injection and define the type that the symbol should resolve to.

const token = new InjectionToken();
const providers = [{ provide: token, factory: () => {}]

The injector would return an error if it is unable to find a provider for the particular token.

deebloo avatar May 16 '24 17:05 deebloo