/// <summary> /// Determines whether the specified <see cref="System.Object"/> is equal to this instance. /// </summary> /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param> /// <returns> /// Value of <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>. /// </returns> public override bool Equals(object obj) { RecursiveResolutionStrategy other = obj as RecursiveResolutionStrategy; if (other == null) { return(false); } return(this.implementationType == other.implementationType); }
internal bool TryCreateObject(Type targetType, Type contractType, bool throwOnError, out object value) { this.Logger.WriteLine(LogLevel.Trace, "Lightweight Dependency Injector[depth:{0}].Try Create Object(target type:'{1}', contract type:'{2}', throw On Error:'{3}' out value)", this.containerdepth, targetType == null ? "null" : targetType.FullName, contractType.FullName, throwOnError.ToString()); if (this.injectedDependencies.TryGetValue(contractType, out value) || this.locallyCreatedDependencies.TryGetValue(contractType, out value)) { if (value != constructingMarker) { return(true); } else { if (throwOnError) { throw new TaupoInvalidOperationException("Attempt to recursively construct " + contractType); } return(false); } } IResolutionStrategy strategy; if (!this.resolutionStrategies.TryGetValue(contractType, out strategy)) { if (contractType.IsAbstract() || contractType.IsInterface()) { if (throwOnError) { string message = "No implementation defined for " + contractType; if (targetType != null) { message += " (dependency of " + targetType.FullName + ")"; } throw new TaupoInvalidOperationException(message); } return(false); } else { // otherwise try to create the contract type itself strategy = new RecursiveResolutionStrategy(contractType); } } this.locallyCreatedDependencies.Add(contractType, constructingMarker); try { ResolutionContext context = new ResolutionContext { Container = this, TargetType = targetType, ThrowOnError = false, }; if (strategy.TryResolve(context, out value)) { this.AddConstructedObject(contractType, value); return(true); } else if (throwOnError) { // will throw context.ThrowOnError = true; strategy.TryResolve(context, out value); } } finally { if (this.locallyCreatedDependencies[contractType] == constructingMarker) { this.locallyCreatedDependencies.Remove(contractType); } } return(false); }