Annotation Interface Service


@Target(TYPE) @Retention(RUNTIME) public @interface Service
Annotation to mark a class as a service for dependency injection
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Class<?>[]
    The type(s) this service should be registered under in the registry.
    When specified, the service instance can be injected by these types (typically interfaces or abstract classes) instead of the concrete class.
    The service is always also registered under its own concrete class.
    Default is no additional bindings.
    boolean
    Whether the service should be eagerly loaded upon registration.
    If true, the service will be instantiated immediately when registered.
    If false, the service will be instantiated lazily when first requested.
    Default is false (lazy loading).
    The scope of the service instance.
    ServiceScope.SINGLETON - A single instance is shared across the application.
    ServiceScope.PROTOTYPE - A new instance is created each time it is requested.
    Default is ServiceScope.SINGLETON.
  • Element Details

    • eagerlyLoad

      boolean eagerlyLoad
      Whether the service should be eagerly loaded upon registration.
      If true, the service will be instantiated immediately when registered.
      If false, the service will be instantiated lazily when first requested.
      Default is false (lazy loading).
      Default:
      false
    • scope

      The scope of the service instance.
      ServiceScope.SINGLETON - A single instance is shared across the application.
      ServiceScope.PROTOTYPE - A new instance is created each time it is requested.
      Default is ServiceScope.SINGLETON.
      Default:
      SINGLETON
    • binds

      Class<?>[] binds
      The type(s) this service should be registered under in the registry.
      When specified, the service instance can be injected by these types (typically interfaces or abstract classes) instead of the concrete class.
      The service is always also registered under its own concrete class.
      Default is no additional bindings.
       @Service(binds = Storage.class)
       public class MySQLStorage implements Storage { ... }
      
       // Now this works:
       @Inject Storage storage;
       
      Default:
      {}