Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/karbonitekream/injektor
A simple dependency injection container for Java
https://github.com/karbonitekream/injektor
Last synced: 23 days ago
JSON representation
A simple dependency injection container for Java
- Host: GitHub
- URL: https://github.com/karbonitekream/injektor
- Owner: KarboniteKream
- License: mit
- Created: 2020-07-23T08:14:36.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-07-26T12:22:58.000Z (over 4 years ago)
- Last Synced: 2023-07-04T15:10:32.107Z (over 1 year ago)
- Language: Java
- Homepage:
- Size: 81.1 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# injektor
A simple dependency injection container for Java.
## Example
```java
import io.kream.injektor.Injektor;
import io.kream.injektor.context.Context;
import io.kream.injektor.context.ValueFactory;import javax.inject.Inject;
public class Main {
public static void main(String[] args) {
final Context context = Context.create();
context.register(Counter.class, ValueFactory.of(new Counter()));final Injektor injektor = Injektor.create(context);
final CounterDelegate counter = injektor.getInstance(CounterDelegate.class);
}static class CounterDelegate {
private final Counter delegate;@Inject
CounterDelegate(Counter delegate) {
this.delegate = delegate;
}public int get() {
return delegate.get();
}public void increment() {
delegate.increment();
}
}static class Counter {
private int count;public int get() {
return count;
}public void increment() {
count++;
}
}
}
```