예제 #1
0
 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);
 }
예제 #2
0
 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;
 }
예제 #3
0
        /// <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);
        }
예제 #4
0
        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;
        }
예제 #5
0
        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));
        }
예제 #6
0
 public ResolveContext(ResolveContext outerContext, Type resolvingType)
 {
     _outerContext = outerContext;
     _resolvingType = resolvingType;
 }
예제 #7
0
 public virtual object Resolve(ResolveContext context)
 {
     return _instance;
 }
예제 #8
0
 public virtual bool CanResolve(ResolveContext context)
 {
     return context.ResolvingType == _forType;
 }
예제 #9
0
 public virtual object Resolve(ResolveContext context)
 {
     return(_instance);
 }
예제 #10
0
 public virtual bool CanResolve(ResolveContext context)
 {
     return(context.ResolvingType == _forType);
 }