Class ParameterInjectorRegistry<C>
java.lang.Object
cloud.commandframework.annotations.injection.ParameterInjectorRegistry<C>
- Type Parameters:
C- Command sender type
- All Implemented Interfaces:
InjectionService<C>,cloud.commandframework.services.types.Service<Triplet<CommandContext<C>,,Class<?>, AnnotationAccessor>, Object> Function<Triplet<CommandContext<C>,Class<?>, AnnotationAccessor>, Object>
@API(status=STABLE,
since="1.2.0")
public final class ParameterInjectorRegistry<C>
extends Object
implements InjectionService<C>
Registry containing mappings between
Class Predicates
and injectors.
The order injectors are tested is the same order they were registered in.- Since:
- 1.2.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<@NonNull T>
@NonNull Optional<T>getInjectable(@NonNull Class<@NonNull T> clazz, @NonNull CommandContext<C> context, @NonNull AnnotationAccessor annotationAccessor) Attempt to get an injectable value for the given context.@Nullable Objecthandle(@NonNull Triplet<CommandContext<C>, Class<?>, AnnotationAccessor> triplet) <T> @NonNull Collection<@NonNull ParameterInjector<C,?>> Deprecated.Inject directly instead of relying on this listvoidregisterInjectionService(InjectionService<C> service) Register an injection service that will be able to provide injections usinggetInjectable(Class, CommandContext, AnnotationAccessor).<T> voidregisterInjector(@NonNull Class<T> clazz, @NonNull ParameterInjector<C, T> injector) Register an injector for a particular type or any of it's assignable supertypes.<T> voidregisterInjector(@NonNull Predicate<Class<?>> predicate, @NonNull ParameterInjector<C, T> injector) Register an injector for a particular type predicate.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface cloud.commandframework.services.types.Service
apply, order
-
Constructor Details
-
ParameterInjectorRegistry
public ParameterInjectorRegistry()Create a new parameter injector registry
-
-
Method Details
-
registerInjector
Register an injector for a particular type or any of it's assignable supertypes.- Type Parameters:
T- Injected type- Parameters:
clazz- Type that the injector should inject for. This type will matched usingClass.isAssignableFrom(Class)injector- The injector that should inject the value into the command method
-
registerInjector
@API(status=STABLE, since="1.8.0") public <T> void registerInjector(@NonNull Predicate<Class<?>> predicate, @NonNull ParameterInjector<C, T> injector) Register an injector for a particular type predicate.The predicate should only return true if the injected type is assignable to the tested type. This predicate overload is provided in addition to
registerInjector(Class, ParameterInjector)to allow for exact, non-exact, or custom predicates, however is still bound by the aforementioned constraint. Failure to adhere to this will result in runtime exceptions.- Type Parameters:
T- Injected type- Parameters:
predicate- A predicate that matches if the injector should be used for a typeinjector- The injector that should inject the value into the command method- Since:
- 1.8.0
-
injectors
@Deprecated public <T> @NonNull Collection<@NonNull ParameterInjector<C,?>> injectors(@NonNull Class<T> clazz) Deprecated.Inject directly instead of relying on this listGet a collection of all injectors that could potentially inject a value of the given type. This does not include injectors from external injector services, instead it only uses injectors registered usingregisterInjector(Class, ParameterInjector).- Type Parameters:
T- Generic type- Parameters:
clazz- Type to query for- Returns:
- Immutable collection containing all injectors that could potentially inject a value of the given type
-
handle
public @Nullable Object handle(@NonNull Triplet<CommandContext<C>, Class<?>, AnnotationAccessor> triplet) - Specified by:
handlein interfacecloud.commandframework.services.types.Service<Triplet<CommandContext<C>,Class<?>, AnnotationAccessor>, Object>
-
getInjectable
@API(status=STABLE, since="1.4.0") public <@NonNull T> @NonNull Optional<T> getInjectable(@NonNull Class<@NonNull T> clazz, @NonNull CommandContext<C> context, @NonNull AnnotationAccessor annotationAccessor) Attempt to get an injectable value for the given context. This will consider all registeredinjection services, and not just theinjectorsregistered usingregisterInjector(Class, ParameterInjector).- Type Parameters:
T- Type to inject- Parameters:
clazz- Class of the to injectcontext- The command context that requests the injectionannotationAccessor- Annotation accessor for the injection. If the object is requested without access to annotations, useAnnotationAccessor.empty()- Returns:
- The injected value, if an injector was able to provide a value
- Since:
- 1.4.0
-
registerInjectionService
@API(status=STABLE, since="1.4.0") public void registerInjectionService(InjectionService<C> service) Register an injection service that will be able to provide injections usinggetInjectable(Class, CommandContext, AnnotationAccessor).- Parameters:
service- Service implementation- Since:
- 1.4.0
-