@Documented @Retention(value=RUNTIME) @Target(value={TYPE,ANNOTATION_TYPE}) public @interface GenericImplementation
Repository
or an 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
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 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:
@GenericImplementation @SomeQualifier public class SomeGenericRepository<A extends AggregateRoot<ID>, ID> implements Repository<A, ID> { @Inject public SomeGenericRepository( @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 { @Inject @SomeQualifier private Repository<SomeAggregate, SomeId> someAggregateRepository; }
Copyright © 2013-2018–2019 SeedStack. All rights reserved.