[ngtsc] Link dependencies injected with @Inject decorator with the provider
GrandSchtroumpf opened this issue · comments
The problem
With this example :
const TOKEN = new InjectionToken();
@Component({
...
providers: [{ provide: TOKEN, useValue: true }]
})
export class MainComponent {
constructor(@Inject(TOKEN) isTrue) {}
}
@NgModule({
declarations: [MainComponent],
providers: [{ provide: TOKEN, useValue: false }]
})
When running :
const [component] = workspace.getAllComponents();
const [token] = component.getDependencies();
The value token
should reference the provider inside the component (with the value true
).
Current behavior: returns undefined.
How to solve :
- Do more research on the compiler to found out if this information is hold somewhere
- If not create a
ProviderRegistry
that keeps track of all the provider per class declaration or at the root ifprovidedIn: 'root'
- For components & directives we can use the scope to look for the closest implementation of the provider.
- For injectables & Pipes there is no scope available, we should scan every modules & root field of the
ProviderRegistry
.
Hopefully there is a built-in solution in the angular compiler so we can stop at step 1