示例#1
0
        public void Test_Should_Find_GlobalBeanConfig()
        {
            var beanOptions = new BeanOptions();

            beanOptions.UseGlobalBeanName("Global");
            var beanConfig = beanOptions.FindBeanConfig(typeof(ILangBean));

            Assert.Equal("Global", beanConfig.BeanName);
            Assert.False(beanConfig.ThrowExceptionIfNotFound);
        }
示例#2
0
        public void Test_Should_Find_InterfaceBeanConfig()
        {
            var beanOptions = new BeanOptions();

            beanOptions.UseGlobalBeanName("Global");
            beanOptions.UseBeanNameWithError(typeof(ILangBean), "Spanish");
            var beanConfig = beanOptions.FindBeanConfig(typeof(ILangBean));

            Assert.Equal("Spanish", beanConfig.BeanName);
            Assert.True(beanConfig.ThrowExceptionIfNotFound);
        }
示例#3
0
        /// <summary>
        /// This function uses BeanFinder to discover beans and then register in service collection.
        /// </summary>
        /// <param name="services">Service Collection</param>
        /// <param name="assemblyNames">Name of the assemblies where Beans will be looked for</param>
        /// <param name="beanOptions">Bean Options to be applied when discover beans</param>
        private static void DiscoverBeans(IServiceCollection services, List <AssemblyName> assemblyNames, BeanOptions beanOptions)
        {
            var beanFinder = new BeanFinder();
            var beanGroup  = beanFinder.GetBeanTypes(assemblyNames, beanOptions.IgnoredBeanList);

            beanGroup.InterfaceBeans.ForEach(interfaceBean =>
            {
                var beanConfig = beanOptions.FindBeanConfig(interfaceBean.TInterface);
                var beanData   = interfaceBean.FindBean(beanConfig);
                RegisterTypeInServiceCollection(services, interfaceBean.TInterface, beanData);
            });
            beanGroup.SingleBeans.ForEach(beanData => RegisterTypeInServiceCollection(services, beanData));
        }