public void Inject(object what) { var tk = new TypeKey(what.GetType()); Node n = new Node(tk); n.Value = what; ResultNode rn = new ResultNode(tk,n); var bn = inspector.Inspect(n.Build); rn.BuildNode = bn; foreach (var op in bn.Injections) { var cn = context.ResolveType(new TypeKey(op.PropertyType)); consider.Enqueue(cn); } readyToFill.Enqueue(rn); Build(); }
public ResultNode(TypeKey tk, Node node) { this.node = node; }
private ResultNode CreateResultNode(Stack<TypeKey> tried, Node n) { var tk = n.TypeKey; if (tried.Contains(tk)) { throw new CircularConstructorDependencyException(tried); } tried.Push(tk); try { ResultNode rn; if (nodes.TryGetValue(n.TypeKey, out rn)) { return rn; } rn = new ResultNode(tk, n); nodes[tk] = rn; if (n.Value != null) { resolvedNodes[tk] = rn; return rn; } else { var bn = inspector.Inspect(n.Build); rn.BuildNode = bn; ConstructorInfo ctor = bn.Constructor; if (ctor == null) throw new NoSuiteableInjectionConstructorException(bn.Type); var argts = ctor.GetParameters(); if (argts.Length > 0) { var argns = new ResultNode[argts.Length]; int i = 0; foreach (var parameterInfo in argts) { var pn = context.ResolveType(new TypeKey(parameterInfo.ParameterType)); var arn = CreateResultNode(tried, pn); argns[i] = arn; ++i; } rn.CtorArgs = argns; } readyToConstruct.Enqueue(rn); nodes[tk] = rn; foreach (var op in bn.Injections) { var cn = context.ResolveType(new TypeKey(op.PropertyType)); consider.Enqueue(cn); } return rn; } } finally { tried.Pop(); } }