https://github.com/neziw/dependencyinjector
A lightweight and easy-to-use dependency injection framework in Java
https://github.com/neziw/dependencyinjector
dependencies dependency-injection dependencyinjection di gradle java java-reflection java-reflection-api maven reflection reflections
Last synced: 2 months ago
JSON representation
A lightweight and easy-to-use dependency injection framework in Java
- Host: GitHub
- URL: https://github.com/neziw/dependencyinjector
- Owner: neziw
- License: mit
- Created: 2024-10-21T18:57:37.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-09-29T16:50:36.000Z (3 months ago)
- Last Synced: 2025-09-29T18:38:55.655Z (3 months ago)
- Topics: dependencies, dependency-injection, dependencyinjection, di, gradle, java, java-reflection, java-reflection-api, maven, reflection, reflections
- Language: Java
- Homepage:
- Size: 224 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# DependencyInjector
A lightweight and easy-to-use dependency injection framework in Java, featuring constructor-based injection and automatic post-construction method invocation with `@Inject` and `@PostConstruct` annotations.
### Example Usage:
```java
import ovh.neziw.injector.Injector;
public final class MyApplication {
public static void main(final String[] args) {
final Injector injector = new Injector();
injector.bind(FirstService.class, new FirstService());
injector.bind(SecondService.class, new SecondService());
final MyClass myClass = injector.createInstance(MyClass.class);
myClass.sendMessages();
}
}
```
```java
import ovh.neziw.injector.Inject;
import ovh.neziw.injector.PostConstruct;
public class MyClass {
private final FirstService firstService;
private final SecondService secondService;
@Inject
public MyClass(final FirstService firstService, final SecondService secondService) {
this.firstService = firstService;
this.secondService = secondService;
}
@PostConstruct
void init() {
System.out.println("Example PostConstruct method called");
}
public void sendMessages() {
this.firstService.doSomething();
System.out.println(this.secondService.getSecondServiceMessage());
}
}
```
```java
public class FirstService {
public void doSomething() {
System.out.println("Sending something from FirstService");
}
}
public class SecondService {
public String getSecondServiceMessage() {
return "This is the second service message!";
}
}
```
**Output**:
```
> Example PostConstruct method called
> Sending something from FirstService
> This is the second service message!
```
### Adding dependency
**Maven:**
```xml
neziw-repo
https://repo.neziw.ovh/releases
ovh.neziw
DependencyInjector
1.0.0
```
**Gradle:**
```groovy
repositories {
maven {
name "neziw-repo"
url "https://repo.neziw.ovh/releases"
}
}
implementation "ovh.neziw:DependencyInjector:1.0.0"
```
---
Special thanks to [JetBrains](https://www.jetbrains.com/products/) company for providing development tools used to develop this project.
[
](https://www.jetbrains.com)