https://github.com/eis/minimal-di
This is a minimal dependency injection framework.
https://github.com/eis/minimal-di
java11 java16 java7 java8
Last synced: 10 months ago
JSON representation
This is a minimal dependency injection framework.
- Host: GitHub
- URL: https://github.com/eis/minimal-di
- Owner: eis
- License: apache-2.0
- Created: 2014-12-03T18:22:57.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2021-06-29T16:53:46.000Z (over 4 years ago)
- Last Synced: 2025-01-20T13:23:28.190Z (11 months ago)
- Topics: java11, java16, java7, java8
- Language: Java
- Homepage: http://eis.github.io/minimal-di/project-info.html
- Size: 731 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Minimal DI
==========
[](https://github.com/eis/minimal-di/actions/workflows/build.yml)
[](https://codecov.io/gh/eis/minimal-di)
[](https://maven-badges.herokuapp.com/maven-central/com.github.eis.libraries/minimal-di/)
[](https://codebeat.co/projects/github-com-eis-minimal-di)
This is a minimal dependency injection framework.
Reasoning
---------
This was created out of need for simple DI. Guice weighs 600kt, Weld
CDI 3M, and Spring even more. Even PicoContainer weighs 317kt.
That's not what I needed - I needed a very simple DI system
that would just implement the basic features and nothing more, with
few simple classes. This is it.
"Minimal DI" currently weighs 23k as a .jar, which is simple enough.
It doesn't need any additional dependencies which was one of
its main goals.
Usage
-----
Inject your dependencies to constructors:
```java
import fi.eis.libraries.di.Inject;
public class CurrentApp {
private MyDependency dependency;
@Inject
public CurrentApp(MyDependency dependency) {
this.dependency = dependency;
}
}
```
Or directly to your private variables:
```java
import fi.eis.libraries.di.Inject;
public class CurrentApp {
@Inject
private MyDependency dependency;
}
```
and fire up the system using either all classes in the deployment unit:
```java
public static void main(String args[]) {
Context diContext = DependencyInjection.deploymentUnitContext(CurrentApp.class);
CurrentApp app = diContext.get(CurrentApp.class);
app.run();
}
```
or listing all implementation classes part of DI:
```java
public static void main(String args[]) {
Module module = DependencyInjection.classes(CurrentApp.class, ClassImplementingDependency.class);
Context diContext = DependencyInjection.context(module);
CurrentApp app = diContext.get(CurrentApp.class);
app.run();
}
```
or use a Spring-style javaconfig class (version 1.1):
```java
public static void main(String args[]) {
Context diContext = DependencyInjection.configurationClasses(ExampleJavaConfig.class);
CurrentApp app = diContext.get(CurrentApp.class);
app.run();
}
```
That's it.
Maven dependency
----------------
This library can be used from Maven Central:
```xml
com.github.eis.libraries
minimal-di
1.1
```