Exemplo n.º 1
0
        /// <summary>
        /// 初始化注入列表
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private List <IInjector> InitializeInjector(Type type)
        {
            List <IInjector> injectors = new List <IInjector>();

            if (type != typeof(object))
            {
                PropertyInfo[] propertyInfos = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                foreach (PropertyInfo propertyInfo in propertyInfos)
                {
                    InjectAttribute injectionAttribute = propertyInfo.GetCustomAttributeEx <InjectAttribute>();
                    if (injectionAttribute != null)
                    {
                        string name = injectionAttribute.Value ?? propertyInfo.Name;
                        injectors.Add(new PropertyInjector(this, propertyInfo, name));
                    }
                }
            }

            return(injectors);
        }
Exemplo n.º 2
0
        private void InitializeInjector(Type type, List <IInjector> injectors)
        {
            if (type == typeof(object))
            {
                return;
            }

            InitializeInjector(type.BaseType, injectors);

            PropertyInfo[] propertyInfos = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                InjectAttribute injectionAttribute = propertyInfo.GetCustomAttributeEx <InjectAttribute>();
                if (injectionAttribute != null)
                {
                    string name = injectionAttribute.Value ?? propertyInfo.Name;
                    injectors.Add(new PropertyInjector(this.Container, propertyInfo, name));
                }
            }
        }
Exemplo n.º 3
0
        public ConstructorInjector(IContainer container, Type type)
        {
            this.Container          = container;
            this.Type               = type;
            this.ConstructorInfo    = this.GetConstructorInfo(type);
            this.ParameterInjectors = new List <ParameterInjector>();

            ParameterInfo[] parameterInfos = this.ConstructorInfo.GetParameters();

            if (parameterInfos != null && parameterInfos.Length > 0)
            {
                foreach (ParameterInfo parameterInfo in parameterInfos)
                {
                    InjectAttribute injectionAttribute = parameterInfo.GetCustomAttributeEx <InjectAttribute>();
                    string          injectValue        = injectionAttribute.Value ?? parameterInfo.ParameterType.FullName;
                    Identity        identity           = new Identity(parameterInfo.ParameterType.TypeHandle, injectValue);
                    this.ParameterInjectors.Add(new ParameterInjector(container, container.GetFactory(identity)));
                }
            }

            this.Injectors = container.GetInjectors(type);
        }