Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 15 hours 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 (24 days ago)
- Default Branch: master
- Last Pushed: 2024-11-11T18:07:20.000Z (3 days ago)
- Last Synced: 2024-11-11T19:20:22.504Z (3 days ago)
- Topics: dependencies, dependency-injection, dependencyinjection, di, gradle, java, java-reflection, java-reflection-api, maven, reflection, reflections
- Language: Java
- Homepage:
- Size: 79.1 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
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)