Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2017-2020 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.context;
import io.micronaut.context.exceptions.NoSuchBeanException;
import io.micronaut.core.annotation.Experimental;
import io.micronaut.core.type.Argument;
import io.micronaut.core.util.ArgumentUtils;
import io.micronaut.inject.BeanConfiguration;
import io.micronaut.inject.BeanDefinition;
import io.micronaut.inject.BeanDefinitionReference;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.inject.ProxyBeanDefinition;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import java.util.Optional;
/**
*
*
* @author Graeme Rocher
* @since 1.0
*/
public interface BeanDefinitionRegistry {
/**
* Return whether the bean of the given type is contained within this context.
*
* @param beanType The bean type
* @param qualifier The qualifier for the bean
* @param The concrete type
* @return True if it is
*/
boolean containsBean(@NonNull Class beanType, @Nullable Qualifier qualifier);
/**
* Return whether the bean of the given type is contained within this context.
*
* @param beanType The bean type
* @param qualifier The qualifier for the bean
* @param The concrete type
* @return True if it is
* @since 3.0.0
*/
default boolean containsBean(@NonNull Argument beanType, @Nullable Qualifier qualifier) {
return containsBean(
Objects.requireNonNull(beanType, "Bean type cannot be null").getType(),
qualifier
);
}
/**
* Return whether the bean of the given type is contained within this context.
*
* @param beanType The bean type
* @param The concrete type
* @return True if it is
* @since 3.0.0
*/
default boolean containsBean(@NonNull Argument beanType) {
return containsBean(
Objects.requireNonNull(beanType, "Bean type cannot be null"),
null
);
}
/**
* Registers a new reference at runtime. Not that registering beans can impact
* the object graph therefore should this should be done as soon as possible prior to
* the creation of other beans preferably with a high priority {@link io.micronaut.context.annotation.Context} scope bean.
*
* @param definition The reference.
* @return The registry
* @param The bean type
* @since 3.6.0
*/
@NonNull
@Experimental
default BeanDefinitionRegistry registerBeanDefinition(@NonNull RuntimeBeanDefinition definition) {
throw new UnsupportedOperationException("This implementation of BeanDefinitionRegistry doesn't support runtime registration of bean definitions");
}
/**
*
Registers a new singleton bean at runtime. This method expects that the bean definition data will have been
* compiled ahead of time.
*
*
If bean definition data is found the method will perform dependency injection on the instance followed by
* invoking any {@link jakarta.annotation.PostConstruct} hooks.
*
*
If no bean definition data is found the bean is registered as is.
*
* @param type The bean type
* @param singleton The singleton bean
* @param qualifier The bean qualifier
* @param inject Whether the singleton should be injected (defaults to true)
* @param The concrete type
* @return This bean context
*/
@NonNull BeanDefinitionRegistry registerSingleton(
@NonNull
Class type,
@NonNull
T singleton,
@Nullable
Qualifier qualifier,
boolean inject
);
/**
* Obtain a bean configuration by name.
*
* @param configurationName The configuration name
* @return An optional with the configuration either present or not
*/
@NonNull Optional findBeanConfiguration(@NonNull String configurationName);
/**
* Obtain a {@link BeanDefinition} for the given type.
*
* @param beanType The type
* @param qualifier The qualifier
* @param The concrete type
* @return An {@link Optional} of the bean definition
* @throws io.micronaut.context.exceptions.NonUniqueBeanException When multiple possible bean definitions exist
* for the given type
*/
@NonNull Optional> findBeanDefinition(@NonNull Class beanType, @Nullable Qualifier qualifier);
/**
* Obtain a {@link BeanDefinition} for the given type.
*
* @param beanType The potentially parameterized type
* @param qualifier The qualifier
* @param The concrete type
* @return An {@link Optional} of the bean definition
* @throws io.micronaut.context.exceptions.NonUniqueBeanException When multiple possible bean definitions exist
* for the given type
* @since 3.0.0
*/
default @NonNull Optional> findBeanDefinition(@NonNull Argument beanType, @Nullable Qualifier qualifier) {
return findBeanDefinition(
Objects.requireNonNull(beanType, "Bean type cannot be null").getType(),
qualifier
);
}
/**
* Obtain a {@link BeanDefinition} for the given type.
*
* @param beanType The potentially parameterized type
* @param The concrete type
* @return An {@link Optional} of the bean definition
* @throws io.micronaut.context.exceptions.NonUniqueBeanException When multiple possible bean definitions exist
* for the given type
* @since 3.0.0
*/
default @NonNull Optional> findBeanDefinition(@NonNull Argument beanType) {
return findBeanDefinition(beanType, null);
}
/**
* Obtain a {@link BeanRegistration} for the given bean.
*
* @param bean The bean
* @param The concrete type
* @return An {@link Optional} of the bean definition
* @throws io.micronaut.context.exceptions.NonUniqueBeanException When multiple possible bean definitions exist
* for the given type
*/
@NonNull Optional> findBeanRegistration(@NonNull T bean);
/**
* Obtain a {@link BeanDefinition} for the given bean.
*
* @param bean The bean
* @param The concrete type
* @return An {@link Optional} of the bean definition
* @throws io.micronaut.context.exceptions.NonUniqueBeanException When multiple possible bean definitions exist
* for the given type
* @since 4.3.0
*/
@NonNull
default Optional> findBeanDefinition(@NonNull T bean) {
return findBeanRegistration(bean).map(BeanRegistration::getBeanDefinition);
}
/**
* Obtain a {@link BeanDefinition} for the given type.
*
* @param beanType The type
* @param The concrete type
* @return An {@link Optional} of the bean definition
* @throws io.micronaut.context.exceptions.NonUniqueBeanException When multiple possible bean definitions exist
* for the given type
*/
@NonNull Collection> getBeanDefinitions(@NonNull Class beanType);
/**
* Obtain a {@link BeanDefinition} for the given type.
*
* @param beanType The type
* @param The concrete type
* @return An {@link Optional} of the bean definition
* @throws io.micronaut.context.exceptions.NonUniqueBeanException When multiple possible
* bean definitions exist for the given type
* @since 3.0.0
*/
default @NonNull Collection> getBeanDefinitions(@NonNull Argument beanType) {
Objects.requireNonNull(beanType, "Bean type cannot be null");
return getBeanDefinitions(beanType.getType(), null);
}
/**
* Obtain a {@link BeanDefinition} for the given type.
*
* @param beanType The type
* @param qualifier The qualifier
* @param The concrete type
* @return An {@link Optional} of the bean definition
* @throws io.micronaut.context.exceptions.NonUniqueBeanException When multiple possible bean definitions exist
* for the given type
*/
@NonNull Collection> getBeanDefinitions(@NonNull Class beanType, @Nullable Qualifier qualifier);
/**
* Obtain a {@link BeanDefinition} for the given type.
*
* @param beanType The type
* @param qualifier The qualifier
* @param The concrete type
* @return An {@link Optional} of the bean definition
* @throws io.micronaut.context.exceptions.NonUniqueBeanException When multiple possible
* bean definitions exist for the given type
* @since 3.0.0
*/
default @NonNull Collection> getBeanDefinitions(@NonNull Argument beanType, @Nullable Qualifier qualifier) {
Objects.requireNonNull(beanType, "Bean type cannot be null");
return getBeanDefinitions(beanType.getType(), qualifier);
}
/**
* Get all of the {@link BeanDefinition} for the given qualifier.
*
* @param qualifier The qualifier
* @return The bean definitions
*/
@NonNull Collection> getBeanDefinitions(@NonNull Qualifier