/// <summary>
        /// 默认是类名首字母小写生成别名
        /// </summary>
        /// <param name="definition"></param>
        /// <returns></returns>
        private string BuildDefaultName(BeanDefinition definition)
        {
            // 获取类名称
            string className = definition.BeanClass.Name;
            string beanName  = className.Substring(0, 1).ToLower() + className.Substring(1);

            return(beanName);
        }
        /// <summary>
        /// 生成beanName的方法
        /// </summary>
        /// <param name="definition"></param>
        /// <returns></returns>
        public string GeneratorBeanName(BeanDefinition definition)
        {
            // 获取Type类型对象上面的ComponetAttribute特性
            var    attr     = definition.BeanClass.GetCustomAttribute <ComponetAttribute>(false);
            string beanName = attr.BeanName;

            if (!string.IsNullOrEmpty(beanName))
            {
                return(beanName);
            }

            // 按照默认方式生成
            return(BuildDefaultName(definition));
        }
示例#3
0
        /// <summary>
        /// 设置BeanDefinition的作用域
        /// </summary>
        /// <param name="definition"></param>
        /// <returns></returns>
        public string ConfigScope(BeanDefinition definition)
        {
            // 规则实例的默认作用域为Singleton
            string scopeName = BeanDefinition.SINGLETION_SCOPE;
            var    attr      = definition.BeanClass.GetCustomAttribute <ScopeAttribute>();

            if (null != attr)
            {
                string scopeString = attr.Name;
                if (!string.IsNullOrEmpty(scopeString))
                {
                    scopeName = scopeString;
                }
            }

            return(scopeName);
        }
示例#4
0
 //this => IOCScanningConfigApplictionContext实例
 public static void BeanRegistry(BeanDefinition beanDefinition, IRegistryBeanDefinition registry)
 {
     registry.RegistryBeanDefinition(beanDefinition.BeanName, beanDefinition);
 }