public bool IsRegistered(Type type, string instanceName = null) { if (type == null) { throw new ArgumentNullException(nameof(type)); } var key = new MappingKey(type, instanceName); return(mappings.ContainsKey(key)); }
private Type LookUpDependency(Type type, string instanceName) { if (type == null) { throw new ArgumentNullException(nameof(type)); } var key = new MappingKey(type, instanceName); if (mappings.TryGetValue(key, out var createInstance)) { var instance = createInstance(); return(instance.GetType()); } const string errorMessageFormat = "Could not find mapping for type '{0}'"; throw new InvalidOperationException(string.Format(errorMessageFormat, type.FullName)); }
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)); }
public void Register(Type type, Func <object> createInstanceDelegate, string instanceName = null) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (createInstanceDelegate == null) { throw new ArgumentNullException(nameof(createInstanceDelegate)); } var key = new MappingKey(type, instanceName); if (mappings.ContainsKey(key)) { const string errorMessageFormat = "The requested mapping already exists '{0}'"; throw new InvalidOperationException(errorMessageFormat); } mappings.Add(key, createInstanceDelegate); }