public class SimpleInjector extends Object implements Injector
InjectorFactory can be plugged in for testing.
Given the following class:
class Pojo {
@EJB
private Service service;
...
}
injecting the EJB into a POJO is accomplished as follows:
Pojo pojo = new Pojo();
SimpleInjector injector = new SimpleInjector(InjectorFactoryBuilder
.getInjectorFactory());
injector.inject(pojo);
Of course, the above example assumes the the injector understands the
@EJB annotation (which of course CDI does).
The SimpleInjector should be cached. This is because the
SimpleInjector caches the Injector objects that it uses
internally for performance. This is done because creation of these internal
Injector objects may be costly. Caching the simple injector
makes sure that a class is not analysed again for annotations every time
injection is used.
For more advanced cases, the injector factory can also be directly
constructed instead of being obtained through the InjectorBuilder.| Constructor and Description |
|---|
SimpleInjector(InjectorFactory aFactory)
Constructs the injector.
|
public SimpleInjector(InjectorFactory aFactory)
aFactory - Factory to use.Copyright © 2025. All rights reserved.