Example #1
0
        /// <summary>
        ///  创建Autowired的包装器
        /// </summary>
        /// <param name="autowired"></param>
        /// <param name="type"></param>
        /// <param name="classType"></param>
        /// <param name="typeDescription"></param>
        /// <returns></returns>
        public object CreateAutowiredFactory(Autowired autowired, Type type, Type classType, string typeDescription)
        {
            var           targetType       = type.GenericTypeArguments[0];
            var           valueType        = typeof(AutowiredObjectFactory <>);
            var           valueFactoryType = valueType.MakeGenericType(targetType);
            Func <object> function         = () => autowired.Resolve(classType, targetType, _context, typeDescription);

            return(Activator.CreateInstance(valueFactoryType, new object[] { function }));
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="autowired"></param>
        /// <param name="type"></param>
        /// <param name="classType"></param>
        /// <param name="instance"></param>
        /// <param name="Parameters"></param>
        /// <returns></returns>
        public object CreateAutowiredFactory(Autowired autowired, Type type, Type classType, object instance, IEnumerable <Parameter> Parameters)
        {
            var           targetType       = type.GenericTypeArguments[0];
            var           valueType        = typeof(AutowiredObjectFactory <>);
            var           valueFactoryType = valueType.MakeGenericType(targetType);
            Func <object> function         = () => autowired.Resolve(_context, instance, classType, targetType, Parameters);

            return(Activator.CreateInstance(valueFactoryType, new object[] { function }));
        }
Example #3
0
        /// <summary>
        /// 创建Lazy的包装器
        /// </summary>
        /// <param name="autowired"></param>
        /// <param name="type"></param>
        /// <param name="classType"></param>
        /// <param name="fieldOrPropertyName"></param>
        /// <param name="instance"></param>
        /// <param name="Parameters"></param>
        /// <returns></returns>
        internal object CreateLazyFactory(Autowired autowired, Type type, Type classType, string fieldOrPropertyName, object instance, List <Parameter> Parameters)
        {
            var           targetType       = type.GenericTypeArguments[0];
            var           valueType        = typeof(LazyAutowiredFactory <>);
            var           valueFactoryType = valueType.MakeGenericType(targetType);
            Func <object> function         = () => autowired.Resolve(_context, instance, classType, targetType, fieldOrPropertyName, Parameters);
            var           lazyFactory      = Activator.CreateInstance(valueFactoryType, new object[] { function });

            if (!this._lazyMethodCache.TryGetValue(valueFactoryType, out var _cache))
            {
                _cache = lazyFactory.GetType().GetTypeInfo().GetMethod("CreateLazy").GetReflector();
                this._lazyMethodCache.TryAdd(valueFactoryType, _cache);
            }
            return(_cache.Invoke(lazyFactory));
        }