public DependentItem(DependentItem container, string name, Func <object> factory, DependenceLifecycles lifecycle = DependenceLifecycles.AlwaysNew) { this._ContainerItem = container; this.NominalName = name; this.Lifecycle = lifecycle; if (lifecycle == DependenceLifecycles.AlwaysNew) { this._CreateInstance = factory; } else if (lifecycle == DependenceLifecycles.Constant) { object constantValue = null; bool valueInitted = false; this._CreateInstance = () => { if (valueInitted) { return(constantValue); } lock (this) { if (valueInitted) { return(constantValue); } constantValue = factory(); valueInitted = true; } return(constantValue); }; } }
public DependentItem Register(string name, Func <object> factory, DependenceLifecycles depType = DependenceLifecycles.AlwaysNew) { var depItem = new DependentItem(this, name, factory, depType); this.NamedItems.Add(name, depItem); return(depItem); }
public DependentItem(DependentItem container, string name, object constantValue, Type valueType = null) { this._ContainerItem = container; this.NominalName = name; if (constantValue != null) { this.SubstantiveType = constantValue.GetType(); } else { this.SubstantiveType = valueType; } this.Lifecycle = DependenceLifecycles.Constant; this._CreateInstance = () => constantValue; }