Exemple #1
0
        public object Resolve(object factory, IDependencyContext context)
        {
            if (factory is null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            IIocContainer ioc = context.Ioc;

            if (_parameterTypes.Count == 0)
            {
                return(_method.Invoke(factory, null));
            }

            object[] parameters = new object[_parameterTypes.Count];

            for (int i = 0; i < _parameterTypes.Count; i++)
            {
                var    requestType = _parameterTypes[i];
                object resolved;
                if (requestType.IsArray)
                {
                    resolved = ioc.ResolveAll(requestType.GetElementType());
                }
                else if (typeof(IEnumerable).IsAssignableFrom(requestType) && requestType.GenericTypeArguments.Length > 0)
                {
                    resolved = ioc.ResolveAll(requestType.GenericTypeArguments[0]);
                }
                else
                {
                    resolved = ioc.TryResolve(requestType);
                }

                parameters[i] = resolved;
            }

            return(_method.Invoke(factory, parameters));
        }
Exemple #2
0
 public static void Initialize(IDependencyContext dependencyContext)
 {
     _dependencyContext = dependencyContext;
 }
        public object Resolve(object factory, IDependencyContext context)
        {
            var args = context.GetArguments();

            return(ResolveMethod(factory, args));
        }
 public object Resolve(object factory, IDependencyContext context)
 {
     return(_func(factory, context));
 }
 public object Execute(IDependencyContext context)
 {
     return(Method(context));
 }