protected Frame[] compileFrames(IList <Frame> frames) { // Step 1, resolve all the necessary variables foreach (var frame in frames) { frame.ResolveVariables(this); } // Step 1a;) -- figure out if you can switch to inline service // creation instead of the container. _services?.ReplaceVariables(); // Step 2, calculate dependencies var dependencies = new DependencyGatherer(this, frames); findInjectedFields(dependencies); findSetters(dependencies); // Step 3, gather any missing frames and // add to the beginning of the list dependencies.Dependencies.GetAll().SelectMany(x => x).Distinct() .Where(x => !frames.Contains(x)) .Each(x => frames.Insert(0, x)); // Step 4, topological sort in dependency order return(frames.TopologicalSort(x => dependencies.Dependencies[x], true).ToArray()); }
internal void findSetters(DependencyGatherer dependencies) { var list = new List <Setter>(); dependencies.Variables.Each((key, _) => { if (key is Setter) { list.Add(key.As <Setter>()); } }); _method.Setters = list.ToArray(); }
internal void findInjectedFields(DependencyGatherer dependencies) { // Stupid. Can't believe I haven't fixed this in Baseline var list = new List <InjectedField>(); dependencies.Variables.Each((key, _) => { if (key is InjectedField) { list.Add(key.As <InjectedField>()); } }); _method.Fields = list.ToArray(); }