/*----------------------------------------------------------------------------------------*/ #region Protected Methods: Instances /// <summary> /// Resolves an instance of a bound type. /// </summary> /// <param name="service">The type of instance to resolve.</param> /// <param name="context">The context in which the instance should be resolved.</param> /// <returns>The resolved instance.</returns> protected override object DoResolve(Type service, IContext context) { if (context.Binding == null) { IBinding binding = ResolveBinding(service, context); if (binding == null) { if (context.IsOptional) { if (Logger.IsDebugEnabled) { Logger.Debug("No bindings were found for the service {0}, ignoring since the request was optional", Format.Type(service)); } return(null); } else { // We couldn't resolve a binding for the service, so fail. throw new ActivationException(ExceptionFormatter.CouldNotResolveBindingForType(service, context)); } } context.PrepareForActivation(binding); } if (Logger.IsDebugEnabled) { Logger.Debug("Resolving instance for {0}{1}", Format.Context(context), (context.IsEagerActivation ? " (eager activation)" : "")); } if (context.IsEagerActivation && !context.Plan.Behavior.SupportsEagerActivation) { if (Logger.IsDebugEnabled) { Logger.Debug("This is an eager activation request and the plan's behavior does not support it. Not actually activating an instance."); } return(null); } if (context.Instance == null) { context.Instance = context.Plan.Behavior.Resolve(context); } if (context.ShouldTrackInstance) { context.Scope.Register(context); } return(context.Instance); }