Exemple #1
0
        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(implType, context.RequestedType);

            // 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);
                }
            }
        }
Exemple #2
0
        /// <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();
            }
        }
		public override object Resolve(CreationContext context)
		{
			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);
			}
		}
Exemple #4
0
        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 (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);
            }
        }
		/// <summary>
		/// Returns an instance of the component this handler
		/// is responsible for
		/// </summary>
		/// <param name="context"></param>
		/// <param name="track"></param>
		/// <returns></returns>
		protected override object ResolveCore(CreationContext context, bool track)
		{
			if (!context.HasAdditionalParameters)
			{
				if (CurrentState != HandlerState.Valid && !CanResolvePendingDependencies(context))
				{
					AssertNotWaitingForDependency();
				}
			}

			using(CreationContext.ResolutionContext resCtx = context.EnterResolutionContext(this))
			{
				object instance = lifestyleManager.Resolve(context);

				resCtx.Burden.SetRootInstance(instance, this, track || ComponentModel.LifecycleSteps.HasDecommissionSteps);

				context.ReleasePolicy.Track(instance, resCtx.Burden);

				return instance;
			}
		}