/// <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); } }