private bool HasComponentInValidState(string key, DependencyModel dependency, CreationContext context) { IHandler handler; if (context != null && context.IsResolving) { handler = kernel.LoadHandlerByName(key, dependency.TargetItemType, context.AdditionalArguments); } else { handler = kernel.GetHandler(key); } return(IsHandlerInValidState(handler) && handler.IsBeingResolvedInContext(context) == false); }
private bool LoadByName(IKernelInternal kernel) { if (componentName == null) { return(false); } return(fallbackToResolveByTypeIfNameNotFound == false || kernel.LoadHandlerByName(componentName, componentType, additionalArguments) != null); }
private bool LoadByName(IKernelInternal kernel) { if (componentName == null) { return false; } return fallbackToResolveByTypeIfNameNotFound == false || kernel.LoadHandlerByName(componentName, componentType, additionalArguments) != null; }
protected virtual object ResolveCore(CreationContext context, ComponentModel model, DependencyModel dependency) { var parameter = dependency.Parameter; if (parameter != null) { if (dependency.Reference == null) { converter.Context.Push(model, context); try { if (parameter.Value != null || parameter.ConfigValue == null) { return(converter.PerformConversion(parameter.Value, dependency.TargetItemType)); } else { return(converter.PerformConversion(parameter.ConfigValue, dependency.TargetItemType)); } } catch (ConverterException e) { throw new DependencyResolverException( string.Format("Could not convert parameter '{0}' to type '{1}'.", parameter.Name, dependency.TargetItemType.Name), e); } finally { converter.Context.Pop(); } } } if (typeof(IKernel).IsAssignableFrom(dependency.TargetItemType)) { return(kernel); } IHandler handler; if (dependency.Reference != null) { handler = kernel.LoadHandlerByName(dependency.Reference, dependency.TargetItemType, context.AdditionalArguments); } else { try { handler = TryGetHandlerFromKernel(dependency, context); } catch (HandlerException exception) { if (dependency.HasDefaultValue) { return(dependency.DefaultValue); } throw new DependencyResolverException( string.Format( "Missing dependency.{2}Component {0} has a dependency on {1}, which could not be resolved.{2}Make sure the dependency is correctly registered in the container as a service, or provided as inline argument.", model.Name, dependency.TargetItemType, Environment.NewLine), exception); } if (handler == null) { if (dependency.HasDefaultValue) { return(dependency.DefaultValue); } throw new DependencyResolverException( string.Format( "Cycle detected in configuration.{2}Component {0} has a dependency on {1}, but it doesn't provide an override.{2}You must provide an override if a component has a dependency on a service that it - itself - provides.", model.Name, dependency.TargetItemType, Environment.NewLine)); } } if (handler == null) { return(null); } context = RebuildContextForParameter(context, dependency.TargetItemType); return(handler.Resolve(context)); }