use of cn.taketoday.context.loader.ScopeMetadata in project today-infrastructure by TAKETODAY.
the class AnnotationScopeMetadataResolverTests method resolveScopeMetadataShouldApplyScopedProxyModeToPrototype.
@Test
public void resolveScopeMetadataShouldApplyScopedProxyModeToPrototype() {
this.scopeMetadataResolver = new AnnotationScopeMetadataResolver(INTERFACES);
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithPrototypeScope.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
Assertions.assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull();
Assertions.assertThat(scopeMetadata.getScopeName()).isEqualTo(BeanDefinition.SCOPE_PROTOTYPE);
Assertions.assertThat(scopeMetadata.getScopedProxyMode()).isEqualTo(INTERFACES);
}
use of cn.taketoday.context.loader.ScopeMetadata in project today-infrastructure by TAKETODAY.
the class AnnotationScopeMetadataResolverTests method customRequestScope.
@Test
public void customRequestScope() {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithCustomRequestScope.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
Assertions.assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull();
Assertions.assertThat(scopeMetadata.getScopeName()).isEqualTo("request");
Assertions.assertThat(scopeMetadata.getScopedProxyMode()).isEqualTo(NO);
}
use of cn.taketoday.context.loader.ScopeMetadata in project today-infrastructure by TAKETODAY.
the class AnnotationScopeMetadataResolverTests method customRequestScopeWithAttribute.
@Test
public void customRequestScopeWithAttribute() {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithCustomRequestScopeWithAttributeOverride.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
Assertions.assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull();
Assertions.assertThat(scopeMetadata.getScopeName()).isEqualTo("request");
Assertions.assertThat(scopeMetadata.getScopedProxyMode()).isEqualTo(TARGET_CLASS);
}
use of cn.taketoday.context.loader.ScopeMetadata in project today-infrastructure by TAKETODAY.
the class AnnotationScopeMetadataResolverTests method resolveScopeMetadataShouldNotApplyScopedProxyModeToSingleton.
@Test
public void resolveScopeMetadataShouldNotApplyScopedProxyModeToSingleton() {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithSingletonScope.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
Assertions.assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull();
Assertions.assertThat(scopeMetadata.getScopeName()).isEqualTo(BeanDefinition.SCOPE_SINGLETON);
Assertions.assertThat(scopeMetadata.getScopedProxyMode()).isEqualTo(NO);
}
use of cn.taketoday.context.loader.ScopeMetadata in project today-infrastructure by TAKETODAY.
the class AnnotatedBeanDefinitionReader method doRegisterBean.
/**
* Register a bean from the given bean class, deriving its metadata from
* class-declared annotations.
*
* @param beanClass the class of the bean
* @param name an explicit name for the bean
* @param qualifiers specific qualifier annotations to consider, if any,
* in addition to qualifiers at the bean class level
* @param supplier a callback for creating an instance of the bean
* (may be {@code null})
* @param customizers one or more callbacks for customizing the factory's
* {@link BeanDefinition}, e.g. setting a lazy-init or primary flag
*/
private <T> void doRegisterBean(Class<T> beanClass, @Nullable String name, @Nullable Class<? extends Annotation>[] qualifiers, @Nullable Supplier<T> supplier, @Nullable BeanDefinitionCustomizer[] customizers) {
AnnotatedGenericBeanDefinition definition = new AnnotatedGenericBeanDefinition(beanClass);
if (this.conditionEvaluator.shouldSkip(definition.getMetadata())) {
return;
}
definition.setInstanceSupplier(supplier);
ScopeMetadata scopeMetadata = scopeMetadataResolver.resolveScopeMetadata(definition);
definition.setScope(scopeMetadata.getScopeName());
String beanName = name != null ? name : beanNameGenerator.generateBeanName(definition, registry);
AnnotationConfigUtils.processCommonDefinitionAnnotations(definition);
if (qualifiers != null) {
for (Class<? extends Annotation> qualifier : qualifiers) {
if (Primary.class == qualifier) {
definition.setPrimary(true);
} else if (Lazy.class == qualifier) {
definition.setLazyInit(true);
} else {
definition.addQualifier(new AutowireCandidateQualifier(qualifier));
}
}
}
applyDynamicCustomizers(definition, customizers);
BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(definition, beanName);
definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
Aggregations