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 classes and injectors
Since:
1.2.0
  • Constructor Details

    • ParameterInjectorRegistry

      public ParameterInjectorRegistry()
      Create a new parameter injector registry
  • Method Details

    • registerInjector

      public <T> void registerInjector(@NonNull Class<T> clazz, @NonNull ParameterInjector<C,T> injector)
      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 using Class.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 list
      Get 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 using registerInjector(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 interface cloud.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 registered injection services, and not just the injectors registered using registerInjector(Class, ParameterInjector).
      Type Parameters:
      T - Type to inject
      Parameters:
      clazz - Class of the to inject
      context - The command context that requests the injection
      annotationAccessor - Annotation accessor for the injection. If the object is requested without access to annotations, use AnnotationAccessor.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 using getInjectable(Class, CommandContext, AnnotationAccessor).
      Parameters:
      service - Service implementation
      Since:
      1.4.0