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>
- Since:
- 1.2.0
-
Constructor Summary
-
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 Object
handle
(@NonNull Triplet<CommandContext<C>, Class<?>, AnnotationAccessor> triplet) <T> @NonNull Collection<@NonNull ParameterInjector<C,
?>> Deprecated.Inject directly instead of relying on this listvoid
registerInjectionService
(InjectionService<C> service) Register an injection service that will be able to provide injections usinggetInjectable(Class, CommandContext, AnnotationAccessor)
.<T> void
registerInjector
(@NonNull Class<T> clazz, @NonNull ParameterInjector<C, T> injector) Register an injector for a particular typeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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- 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
-
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:
handle
in 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 theinjectors
registered 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
-