The PAK-Core harbors the core functionality of the PAK-framework. It enables the creation, fetching and execution of Commands.
Every component within the core-module, plays a vital part in PAK. This chapter describes the functionality of the @InjectService
annotation.
1. Basics
@InjectService
can be used for development inside the PAK-framework. Only Services registered within IServiceProvider, or the `ServiceLoader
should be annotated by this annotation.
Therefore, Services from these instances can be injected into the Service, using @InjectService
, so they can access the Services themselves easily.
When used, the annotated field is created, like being passed via a constructor during runtime. Those Services have Services itself,
which are injected from the current context.
Be careful, don’t create cyclic injection dependencies (do not inject a Service, which is already using @InjectService ), as this will lead to a StackOverflowError!
|
2. Usage
One example usage of this annotation, would be within CommandRestService
. IEndpointClientServiceFactory
is
injected, by using @InjectService
.
Listing 1 shows how to use @InjectService
, by injected IEndpointServiceFactory
CommandRestService
injecting IEndpointClientServiceFactory
, by using @InjectService
public class CommandRestService implements ICommandRestService {
/**
* Injected {@link IEndpointClientServiceFactory}, for creating
* {@link IEndpointClientService}, by passing different parameters in the
* constructor
*/
@InjectService (1)
private IEndpointClientServiceFactory endpointClientServiceFactory;
public CommandRestService() {
// Empty constructor
}
@Override
public IEndpointClientService createEndpointClientServiceFor(final String requesterId) {
return this.endpointClientServiceFactory.createWithId(requesterId); (2)
}
}
1 | IEndpointServiceFactory is injected, by using @InjectService . |
2 | Usage of IEndpointClientService as normal variable within CommandRestService . |