See: Description
| Interface | Description |
|---|---|
| Initializable |
This interface marks an initializable object.
|
| Enum | Description |
|---|---|
| Scope |
This enum specifies the scope of a dependency injection.
|
| Annotation Type | Description |
|---|---|
| Inject |
Main annotation of the dependency injection system.
|
| Injectable |
Marks an injectable class and specifies the scope of the injection.
|
In ibello, all dependency injections are performed by the injector. The injector discovers the injectable fields and handles their values. Sometimes a new instance will be created, and sometimes a previously created instance will be used again.
The dependency injection is based on annotations.
Inject annotation marks injectable fields in classes.
The Injectable annotation marks classes suitable for injection.
The value of the annotation is the scope of the injection.
It's one of the constants from Scope type.
During the injection, the injector tries to use a previously created instance from the same scope.
Eg. if the injected class is test-scoped, then only instance created during the same test method
execution is valid for injection. If there is no valid instance, then the injector creates a new one.
If the injected class does not have a scope annotation, then the injector tries to determine the scope from it's superclasses. The scope will be inherited from the nearest superclass which has a scope annotation. If none of the superclasses has scope annotation, then the class will be considered as session-scoped.
The test execution consists of different stages. These are:
Instances of session-scoped classes are valid only for a session. In a new session, whole new instances will be created. Similarly, instances of specification-scoped classes are valid for a specification execution, and instances of test-scoped classes are valid for a single test run. Singleton instances do not lose they validity, so a singleton class has only one instance for the entire program run.
Not all injections can be performed successfully. If the scope of the parent class is bigger that the scope of the injected field, the the injection is forbidden and will result a runtime exception. So you can't inject specification-scoped instances into a session-scoped class.
The injected class should have a default constructor. The injector calls this constructor if a new instance is needed for this class.
If the injected class implements the Initializable interface, and the injector creates a new instance,
then the Initializable#initialize() method will be called automatically on that instance.
During the injection these steps will be performed in the given order:
Initializable interface, then the Initializable#initialize() method will be called.Created by Kornél Simon, 2022