/// <summary> /// Tries to resolve dependency in a given context. /// </summary> /// <param name="context">The context.</param> /// <param name="resolvedObject">The resolved object.</param> /// <returns> /// True if the resolution succeeded, false otherwise. /// </returns> public bool TryResolve(ResolutionContext context, out object resolvedObject) { foreach (ConstructorInfo constructorInfo in this.implementationType.GetInstanceConstructors(true)) { ParameterInfo[] parameterInfos = constructorInfo.GetParameters(); object[] parameterValues = new object[parameterInfos.Length]; bool failed = false; for (int i = 0; i < parameterInfos.Length; ++i) { if (!context.Container.TryCreateObject(this.implementationType, parameterInfos[i].ParameterType, context.ThrowOnError, out parameterValues[i])) { failed = true; break; } } if (!failed) { resolvedObject = constructorInfo.Invoke(parameterValues); foreach (object o in parameterValues) { context.Container.RegisterDependency(resolvedObject, o); } return true; } } resolvedObject = null; if (context.ThrowOnError) { throw new TaupoInvalidOperationException("No appropriate constructor on " + this.implementationType + " could be called."); } return false; }
/// <summary> /// Tries to resolve dependency in a given context. /// </summary> /// <param name="context">The context.</param> /// <param name="resolvedObject">The resolved object.</param> /// <returns> /// True if the resolution succeeded, false otherwise. /// </returns> public bool TryResolve(ResolutionContext context, out object resolvedObject) { resolvedObject = this.resolver(context.TargetType); return resolvedObject != null; }
/// <summary> /// Tries to resolve dependency in a given context. /// </summary> /// <param name="context">The context.</param> /// <param name="resolvedObject">The resolved object.</param> /// <returns> /// True if the resolution succeeded, false otherwise. /// </returns> public bool TryResolve(ResolutionContext context, out object resolvedObject) { resolvedObject = this.implementationObject; return true; }