public bool IsRegistered(Type type, string instanceName = null) { if (type == null) { throw new ArgumentNullException("type"); } var key = new MappingKey(type, instanceName); return(mappings.ContainsKey(key)); }
public object Resolve(Type type, string instanceName = null) { var key = new MappingKey(type, instanceName); Func <object> createInstance; if (mappings.TryGetValue(key, out createInstance)) { var instance = createInstance(); return(instance); } return(null); }
public void Register(Type type, Func <object> createInstanceDelegate, string instanceName = null) { if (type == null) { throw new ArgumentNullException("type"); } if (createInstanceDelegate == null) { throw new ArgumentNullException("createInstanceDelegate"); } var key = new MappingKey(type, instanceName); if (mappings.ContainsKey(key)) { const string errorMessageFormat = "The requested mapping already exists - {0}"; throw new InvalidOperationException(string.Format(errorMessageFormat, key.ToTraceString())); } mappings.Add(key, createInstanceDelegate); }
/// <summary> /// Determines whether the specified object is equal to the current object. /// </summary> /// <param name="obj">The object to compare with the current object</param> /// <returns> /// <c>true</c> if the specified object is equal to the current object; otherwise, <c>false</c>. /// </returns> public override bool Equals(object obj) { if (obj == null) { return(false); } MappingKey compareTo = obj as MappingKey; if (ReferenceEquals(this, compareTo)) { return(true); } if (compareTo == null) { return(false); } return(Type.Equals(compareTo.Type) && string.Equals(InstanceName, compareTo.InstanceName, StringComparison.InvariantCultureIgnoreCase)); }