Component Graph Construction
As part of the compilation phase, injectors build a list of potential components. The potential components (sometimes referred to as bindings) are collected using the follow algorithm.
- Any
@Injectable
,@Fragment
or@StingProvider
annotated types that declared in the@Injector.includes
parameter are added to the "work list". - Any
@Injectable
or@Fragment
annotated types that are enclosed by the injector type are added to the "work list". i.e. The types annotated by the@Injectable
or@Fragment
annotations that are directly nested within the injector class are added. - Take one type of the "work list" and process this type until there are no types left on the work list.
- A type that is annotated with the
@Injectable
annotation is directly added to the list of bindings. - A type annotated with the
@Fragment
annotation add all the components defined by the provider methods to the set of bindings and add all the types declared as part of the@Fragment.includes
to the "work list". - Types annotated by the
@StingProvider
annotation are processed according to the algorithm described in the framework integration document which may result in more types being added to the "work list".
- A type that is annotated with the
- From the potential components, identify the root components and add them to the set of actual components included
in the injector. The "root" components include components that publish the output services as well
as any potential component that is annotated with the
@Eager
annotation. For every component added to the actual component set, resolve the dependencies of the components and add any component required to satisfy the dependencies. - If a dependency of a component can not be resolved by the components in to set of potential components then attempt to lookup the component using the auto-discovery process. An error will be generated if a non-optional dependency remains unresolved at this stage.
- All the components that are added to the injector are ordered so that dependencies are created before consumer components.
- Any components that are annotated with the
@Eager
annotation will have their eagerness propagated to all dependencies.
This component graph construction process ensures that the minimal set of components is created in an order that ensures no dependency constraints are violated.