protected virtual bool CanResolveParameter(ResolveContext context, ParameterInfo parameterInfo) { var type = parameterInfo.ParameterType; IResolver resolver = _locator.FindResolver(type); if (resolver == null) return false; var childContext = new ResolveContext(context, type); return resolver.CanResolve(childContext); }
protected virtual bool CheckForCycle(ResolveContext context) { var current = context.OuterContext; while (current != null) { if (current.ResolvingType == context.ResolvingType) return true; current = current.OuterContext; } return false; }
/// <summary> /// Gets the service object of the specified type. /// </summary> /// <returns> /// A service object of type <paramref name="serviceType"/>.-or- null if there is no service object of type <paramref name="serviceType"/>. /// </returns> /// <param name="serviceType">An object that specifies the type of service object to get. </param><filterpriority>2</filterpriority> public object GetService(Type serviceType) { var resolver = FindResolver(serviceType); if (resolver == null) resolver = new RecursiveResolver(this, serviceType, serviceType); var context = new ResolveContext(null, serviceType); if (!resolver.CanResolve(context)) return null; return resolver.Resolve(context); }
public bool CanResolve(ResolveContext context) { if (context.ResolvingType != _implementedType) return false; if (CheckForCycle(context)) return false; var constructors = GetConstructorsInOrder(); foreach (var constructorInfo in constructors) { var parametersInfos = constructorInfo.GetParameters(); if (parametersInfos.All(parameterInfo => CanResolveParameter(context, parameterInfo))) return true; } return false; }
public object Resolve(ResolveContext context) { var constructors = GetConstructorsInOrder(); foreach (var constructorInfo in constructors) { var parametersInfos = constructorInfo.GetParameters(); if (!parametersInfos.All(parameterInfo => CanResolveParameter(context, parameterInfo))) continue; var parameters = parametersInfos .Select(parameterInfo => ResolveParameter(context, parameterInfo)) .ToArray(); return constructorInfo.Invoke(parameters); } throw new InvalidOperationException(string.Format("Cannot resolve type {0}.", context.ResolvingType)); }
public ResolveContext(ResolveContext outerContext, Type resolvingType) { _outerContext = outerContext; _resolvingType = resolvingType; }
public virtual object Resolve(ResolveContext context) { return _instance; }
public virtual bool CanResolve(ResolveContext context) { return context.ResolvingType == _forType; }
public virtual object Resolve(ResolveContext context) { return(_instance); }
public virtual bool CanResolve(ResolveContext context) { return(context.ResolvingType == _forType); }