private static <T extends ChainedComponent> Chain<T> buildChain(Collection<T> components, Collection<Phase> phases) {
        ChainBuilder<T> builder = new ChainBuilder<>(new ComponentId("temp"));
        for (Phase phase : phases) {
            builder.addPhase(phase);
        }

        for (T component : components) {
            builder.addComponent(component);
        }

        return builder.orderNodes();
    }
Create a chain by using a builder. This will order the chain by the ordering constraints.
container-core/src/main/java/com/yahoo/component/chain/Chain.java