
org.seedstack.business.spi.GenericImplementation Maven / Gradle / Ivy
/*
* Copyright © 2013-2024, The SeedStack authors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.business.spi;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation can be used on an implementation of a
* {@link org.seedstack.business.domain.Repository}
* or an {@link org.seedstack.business.assembler.Assembler} to declare it as a generic
* implementation.
*
* Generic implementations are able to work with all types satisfying the conditions of their
* interface. For instance a generic implementation of a
* {@link org.seedstack.business.domain.Repository}
* must be able to work with any aggregate in the system.
*
* A generic implementation often exist along with user-defined explicit implementations of the
* same interface, so it is recommended to annotate it with a {@code javax.inject.Qualifier},
* leaving the unqualified implementation for user code.
*
* A generic implementation is instantiated through assisted injection, invoking a constructor whose
* unique parameter must be an array of the classes it will work on. Consider the following example:
*
*
*
* {@literal @}GenericImplementation
* {@literal @}SomeQualifier
* public class SomeGenericRepository<A extends AggregateRoot<ID>, ID> implements
* Repository<A, ID> {
* {@literal @}Inject
* public SomeGenericRepository({@literal @}Assisted Object[] genericClasses) {
* // genericClasses contains the aggregate root class and the identifier class
* // this instance must work with
* }
* }
*
*
* This generic implementation can be injected as follows:
*
* public class SomeClass {
* {@literal @}Inject
* {@literal @}SomeQualifier
* private Repository<SomeAggregate, SomeId> someAggregateRepository;
* }
*
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
public @interface GenericImplementation {
}