EnterResolutionContext() public méthode

public EnterResolutionContext ( IHandler handlerBeingResolved, bool requiresDecommission ) : ResolutionContext
handlerBeingResolved IHandler
requiresDecommission bool
Résultat ResolutionContext
		protected override object ResolveCore(CreationContext context, bool track, bool instanceRequired)
		{
			Type implType;
			try
			{
				implType = ComponentModel.Implementation.MakeGenericType(context.GenericArguments);
			}
			catch (ArgumentException)
			{
				// may throw in some cases when impl has generic constraints that service hasn't
				if(instanceRequired)
				{
					throw;
				}
				return null;
			}

			var handler = GetSubHandler(context, implType);

			// so the generic version wouldn't be considered as well
			using(context.EnterResolutionContext(this, false))
			{
				return handler.Resolve(context);
			}
		}
		protected override object ResolveCore(CreationContext context, bool track, bool instanceRequired)
		{
			Type implType = ComponentModel.Implementation.MakeGenericType(context.GenericArguments);

			IHandler handler = GetSubHandler(context, implType);

			// so the generic version wouldn't be considered as well
			using(context.EnterResolutionContext(this, false))
			{
				return handler.Resolve(context);
			}
		}
		/// <summary>
		/// Returns an instance of the component this handler
		/// is responsible for
		/// </summary>
		/// <param name="context"></param>
		/// <param name="requiresDecommission"></param>
		/// <param name="instanceRequired"></param>
		/// <returns></returns>
		protected override object ResolveCore(CreationContext context, bool requiresDecommission, bool instanceRequired)
		{
			if (CanResolvePendingDependencies(context) == false)
			{
				if (instanceRequired == false)
				{
					return null;
				}

				AssertNotWaitingForDependency();
			}
			using (var resolutionContext = context.EnterResolutionContext(this,HasDecomission(requiresDecommission)))
			{
				var instance = lifestyleManager.Resolve(context, resolutionContext.Burden, context.ReleasePolicy);
				return instance;
			}
		}
		/// <summary>
		/// Returns an instance of the component this handler
		/// is responsible for
		/// </summary>
		/// <param name="context"></param>
		/// <param name="requiresDecommission"></param>
		/// <param name="instanceRequired"></param>
		/// <returns></returns>
		protected override object ResolveCore(CreationContext context, bool requiresDecommission, bool instanceRequired)
		{
			if (ResolveImpossible(context))
			{
				if (instanceRequired == false)
				{
					return null;
				}

				AssertNotWaitingForDependency();
			}
			using (var resolutionContext = context.EnterResolutionContext(this))
			{
				var instance = lifestyleManager.Resolve(context);

				resolutionContext.Burden.SetRootInstance(instance, this, HasDecomission(requiresDecommission));
				context.ReleasePolicy.Track(instance, resolutionContext.Burden);

				return instance;
			}
		}
		protected override object Resolve(CreationContext context, bool instanceRequired)
		{
			var implType = GetClosedImplementationType(context, instanceRequired);
			if (implType == null)
			{
				Debug.Assert(instanceRequired == false, "instanceRequired == false");
				return null;
			}

			var handler = GetSubHandler(context, implType);
			// so the generic version wouldn't be considered as well
			using (context.EnterResolutionContext(this, false, false))
			{
				try
				{
					return handler.Resolve(context);
				}
				catch (GenericHandlerTypeMismatchException e)
				{
					throw new HandlerException(
						string.Format(
							"Generic component {0} has some generic dependencies which were not successfully closed. This often happens when generic implementation has some additional generic constraints. See inner exception for more details.",
							ComponentModel.Name), ComponentModel.ComponentName, e);
				}
			}
		}
		protected override object Resolve(CreationContext context, bool instanceRequired)
		{
			var implType = GetClosedImplementationType(context, instanceRequired);
			if (implType == null)
			{
				Debug.Assert(instanceRequired == false, "instanceRequired == false");
				return null;
			}

			var handler = GetSubHandler(context, implType);
			// so the generic version wouldn't be considered as well
			using (context.EnterResolutionContext(this, false, false))
			{
				return handler.Resolve(context);
			}
		}
		/// <summary>
		///   Returns an instance of the component this handler
		///   is responsible for
		/// </summary>
		/// <param name = "context"> </param>
		/// <param name = "requiresDecommission"> </param>
		/// <param name = "instanceRequired"> </param>
		/// <param name = "burden"> </param>
		/// <returns> </returns>
		protected object ResolveCore(CreationContext context, bool requiresDecommission, bool instanceRequired, out Burden burden)
		{
			if (IsBeingResolvedInContext(context))
			{
				var cache = lifestyleManager as IContextLifestyleManager;
				if (cache != null)
				{
					var instance = cache.GetContextInstance(context);
					if (instance != null)
					{
						burden = null;
						return instance;
					}
				}

				if (instanceRequired == false)
				{
					burden = null;
					return null;
				}
				var message = new StringBuilder();
				message.AppendFormat("Dependency cycle has been detected when trying to resolve component '{0}'.",
				                     ComponentModel.Name);
				message.AppendLine();
				message.AppendLine("The resolution tree that resulted in the cycle is the following:");
				context.BuildCycleMessageFor(this, message);

				throw new CircularDependencyException(message.ToString(), ComponentModel);
			}
			if (CanResolvePendingDependencies(context) == false)
			{
				if (instanceRequired == false)
				{
					burden = null;
					return null;
				}

				AssertNotWaitingForDependency();
			}
			try
			{
				using (var ctx = context.EnterResolutionContext(this, requiresDecommission))
				{
					var instance = lifestyleManager.Resolve(context, context.ReleasePolicy);
					burden = ctx.Burden;
					return instance;
				}
			}
			catch (NoResolvableConstructorFoundException)
			{
				throw UnresolvableHandlerException();
			}
		}
		/// <summary>
		///   Returns an instance of the component this handler
		///   is responsible for
		/// </summary>
		/// <param name = "context"></param>
		/// <param name = "requiresDecommission"></param>
		/// <param name = "instanceRequired"></param>
		/// <param name = "burden"></param>
		/// <returns></returns>
		protected object ResolveCore(CreationContext context, bool requiresDecommission, bool instanceRequired, out Burden burden)
		{
			if (CanResolvePendingDependencies(context) == false)
			{
				if (instanceRequired == false)
				{
					burden = null;
					return null;
				}

				AssertNotWaitingForDependency();
			}
			using (var ctx = context.EnterResolutionContext(this, requiresDecommission))
			{
				var instance = lifestyleManager.Resolve(context, context.ReleasePolicy);
				burden = ctx.Burden;
				return instance;
			}
		}
		protected override object ResolveCore(CreationContext context, bool requiresDecommission, bool instanceRequired)
		{
			Type implType;
			try
			{
				// TODO: what if ComponentModel.Implementation is a LateBoundComponent?
				implType = ComponentModel.Implementation.MakeGenericType(context.GenericArguments);
			}
			catch (ArgumentException e)
			{
				// may throw in some cases when impl has generic constraints that service hasn't
				if (instanceRequired == false)
				{
					return null;
				}

				// ok, let's do some investigation now what might have been the cause of the error
				var arguments = ComponentModel.Implementation.GetGenericArguments();
				if (arguments.Length > context.GenericArguments.Length)
				{
					var message =
						string.Format(
							"Requested type {0} has {1} generic parameter(s), whereas component implementation type {2} requires {3}. This means that Windsor does not have enough information to properly create that component for you. This is most likely a bug in your registration code.",
							context.RequestedType, context.GenericArguments.Length, ComponentModel.Implementation, arguments.Length);
					throw new HandlerException(message, e);
				}
				// we have correct number of generic arguments, that means probably some generic constraing was violated.
				// the CLR exception should suffice
				throw;
			}

			var handler = GetSubHandler(context, implType);

			// so the generic version wouldn't be considered as well
			using (context.EnterResolutionContext(this, false))
			{
				return handler.Resolve(context);
			}
		}