io.micronaut.context.annotation.Factory Maven / Gradle / Ivy
/*
* 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.annotation;
import javax.inject.Singleton;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* A factory is a {@link Singleton} that produces one or many other bean implementations.
*
* Each produced bean is defined by method that is annotated with {@link Bean}
*
*
* @Factory
* public class MyFactory {
*
* @Bean
* public MyBean myBean() {
* // create the bean
* }
* }
*
* Methods defined within the body of the class that are annotated with {@link Bean} will be exposed as beans.
*
* You can use a {@link javax.inject.Scope} annotation to control the scope the bean is exposed within. For example for a
* singleton instance you can annotation the method with {@link Singleton}.
*
* Methods annotated with {@link Bean} can accept arguments and Micronaut will attempt to inject those arguments from existing beans or values. For example:
*
*
* @Factory
* public class MyFactory {
*
* @Bean
* public MyBean myBean(@Value("foo.bar") String myValue) {
* // create the bean
* }
* }
*
* @see Bean
* @see Configuration
* @author Graeme Rocher
* @since 1.0
*/
@Singleton
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Factory {
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy