示例#1
0
        public void Test_Should_Set_Correct_Values(string name, bool throwIfNotFound)
        {
            var beanConfig = new BeanConfig(name, throwIfNotFound);

            Assert.Equal(name, beanConfig.BeanName);
            Assert.Equal(throwIfNotFound, beanConfig.ThrowExceptionIfNotFound);
        }
示例#2
0
        public void Test_Should_FindBean()
        {
            var beanCollection = new BeanCollection(typeof(ILangBean));

            beanCollection.AddBean(typeof(SpanishLangBean));
            var beanConfig = new BeanConfig("Spanish", true);
            var beanData   = beanCollection.FindBean(beanConfig);

            Assert.NotNull(beanData);
            Assert.Equal(typeof(SpanishLangBean), beanData.TBean);
        }
示例#3
0
        public void Test_Should_Throw_NotFoundBeanException(string beanName, bool throwExceptionIfNotFound, bool addSpanishLangBean)
        {
            var beanCollection = new BeanCollection(typeof(ILangBean));

            if (addSpanishLangBean)
            {
                beanCollection.AddBean(typeof(SpanishLangBean));
            }
            var beanConfig = new BeanConfig(beanName, throwExceptionIfNotFound);

            Assert.Throws <NotFoundBeanException>(() => beanCollection.FindBean(beanConfig));
        }
示例#4
0
        /// <summary>
        /// Find a Bean given a custom bean configuration.
        /// If the configuration says that no exception should be thrown,
        /// then the first bean of the list is returned (unless list is empty)
        /// <exception cref="MrCoto.BeanDiscovery.Data.Exceptions.NotFoundBeanException">
        /// Thrown when a bean is not found.
        /// </exception>
        /// </summary>
        /// <param name="beanConfig">Bean Configuration that specifies how bean will be resolved.</param>
        /// <returns>Found Bean's data</returns>
        public BeanData FindBean(BeanConfig beanConfig)
        {
            var beanData = BeanList.FirstOrDefault(x => x.BeanName == beanConfig.BeanName);

            if (beanData != null)
            {
                return(beanData);
            }
            if (beanConfig.ThrowExceptionIfNotFound)
            {
                throw new NotFoundBeanException(TInterface, beanConfig.BeanName);
            }
            beanData = BeanList.FirstOrDefault();
            if (beanData != null)
            {
                return(beanData);
            }
            throw new NotFoundBeanException(TInterface, beanConfig.BeanName);
        }
示例#5
0
 /// <summary>
 /// Global beanName to be used when discover beans (default is "Primary").
 /// If no bean is found globally, then an exception should be thrown.
 /// </summary>
 /// <param name="beanName">Name of the bean to be resolved.</param>
 public void UseGlobalBeanNameWithError(string beanName) => GlobalBeanName = new BeanConfig(beanName, throwIfNotFound: true);
示例#6
0
 /// <summary>
 /// Global beanName to be used when discover beans (default is "Primary")
 /// </summary>
 /// <param name="beanName">Name of the bean to be resolved.</param>
 public void UseGlobalBeanName(string beanName) => GlobalBeanName = new BeanConfig(beanName);
示例#7
0
 /// <summary>
 /// BeanOptions Constructor
 /// </summary>
 public BeanOptions()
 {
     GlobalBeanName   = new BeanConfig("Primary");
     InterfaceNameBag = new Dictionary <Type, BeanConfig>();
     IgnoredBeanList  = new List <Type>();
 }