Annotation Interface Service
Annotation to mark a class as a service for dependency injection
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionClass<?>[]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.booleanWhether 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 eagerlyLoadWhether 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
ServiceScope scopeThe 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<?>[] bindsThe 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:
{}
-