All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jvault.annotation.Inject Maven / Gradle / Ivy

package org.jvault.annotation;

import org.jvault.metadata.API;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Annotation to inject the corresponding {@link InternalBean}.
* * Here is two ways to inject Bean.

* * FIRST. FIELD INJECTION *
 * {@code @Inject
 * private HelloToo helloToo;}
 * 
* In this case, inject bean based on the name of the field.
* Alternatively, you can search for bean by entering the bean name as follows. * *
 * {@code @Inject("customNamedHelloToo")
 * private HelloToo helloToo;}
 * 
*
* * SECOND. CONSTRUCTOR INJECTION *
 * {@code @Inject
 * private HelloWorld(@Inject("helloToo") HelloToo helloToo){}}
 * 
* * In this case, @Inject annotation should be marked on the constructor to be used for injection,
* and @Inject annotation should be marked on the constructor parameter to be injected.
* Also, always input the value of @Inject of the marked parameter.

* * If the @Inject-marked parameter of the constructor
* marked with @Inject does not have a value, {@link org.jvault.exceptions.NoDefinedInternalBeanException} is thrown.

* * A class must have at most one constructor marked with @Inject annotation,
* and if two or more constructors marked with @Inject annotation are found, {@link org.jvault.exceptions.DuplicateInjectConstructorException} is thrown.

* * If try to inject bean using @Inject from a class or package that @InternalBean does not allow, a {@link org.jvault.exceptions.DisallowedAccessException} is thrown.

* * If CONSTRUCTOR INJECTION and FIELD INJECTION coexist,
* CONSTRUCTOR INJECTION is always selected, and Bean injection proceeds in constructor injection method. * * @see InternalBean * * @author devxb * @since 0.1 */ @API @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.CONSTRUCTOR}) public @interface Inject { /** * Specifies the name of the bean to be injected. * * @return String - The name of the bean to be injected. * * @author devxb * @since 0.1 */ String value() default ""; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy