The InjectorContainer
class is responsible for handling the injection process, and holding all instances.
Parse all files in a package and register them in the DI container.
public void parseStatic(String packageName)
Register a class in the DI container.
public void register(Class<?> c)
Register a class in the DI container mapped to an abstract class.
public void register(Class<?> abstractC, Class<?> concreteC)
Get an instance for a class in the DI container.
public <T> T get(Class<T> c)
On a field or a constructor, mark this field/constructor to benefit from DI.
On a class, mark this class to benefit from DI, and be Injected in other classes.
- Constructor injection with
@Inject
- Field injection with
@Inject
- Package scanning via
parseStatic
@Injectable
to specify injectable Class, and class that will benefit from DI.- Cyclic DI, so all classes get Injected until all classes are instantiated
- Error handling to automatically stop the DI process in case of missing constructor, instantiation error, non
@Injectable
injection
The src
package acts as a default template app, easily customisable to test the DI container.
The test
package tests various scenario:
- Static file parsing
- Constructor injection
- Field injection
- Class without default constructor
- Class with a non-injectable class