https://github.com/iamteppei/simple-di
A Simple Dependency Injection Framework
https://github.com/iamteppei/simple-di
Last synced: 18 days ago
JSON representation
A Simple Dependency Injection Framework
- Host: GitHub
- URL: https://github.com/iamteppei/simple-di
- Owner: iamteppei
- License: apache-2.0
- Created: 2026-05-24T11:59:45.000Z (19 days ago)
- Default Branch: main
- Last Pushed: 2026-05-24T12:39:29.000Z (19 days ago)
- Last Synced: 2026-05-24T14:21:05.613Z (19 days ago)
- Language: Java
- Size: 94.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# simple-di
A lightweight, modular dependency injection container for Java.
[](https://github.com/iamteppei/simple-di/actions/workflows/ci-cd.yml)
[](#requirements)
[](LICENSE)
## Why simple-di
- Small surface area and straightforward API.
- Modular architecture with a clear split between API and implementation.
- Designed for predictable lifecycle management and testability.
## Project Status
- Active prototype / proof-of-concept.
- API and internals may still evolve.
- Feedback and contributions are welcome.
## Project Structure
- `simple-di-api`: Public DI contracts and interfaces.
- `simple-di-core`: Container implementation, module loader, bootstrap starter, and tests.
## Requirements
- JDK 21
- Gradle Wrapper (included)
This project uses Java toolchains and can auto-download missing JDKs (configured in `gradle.properties`).
## Build and Test
Build all modules:
```bash
./gradlew build
```
Run core tests:
```bash
./gradlew :simple-di-core:test
```
Generate JaCoCo coverage report:
```bash
./gradlew :simple-di-core:jacocoTestReport
```
Coverage reports:
- `simple-di-core/build/reports/jacoco/test/html/index.html`
- `simple-di-core/build/reports/jacoco/test/jacocoTestReport.xml`
## Quick Start
Typical bootstrap flow:
```java
import io.abc.platform.container.pure.impl.ContainerRunner;
import io.abc.shared.di.AppContext;
public class Main {
public static void main(String[] args) {
AppContext context = ContainerRunner.start(args);
// Resolve and use your beans from context.
}
}
```
### Quick Start with ServiceLoader Modules
You can register modules using Java ServiceLoader so they are discovered automatically by `ContainerRunner.start(...)`.
1. Create a module implementation and configure bindings:
```java
package com.example;
import io.abc.shared.di.ConfigurableContext;
import io.abc.shared.di.ConfigurableModule;
import io.abc.shared.di.Scope;
public class GreetingModule implements ConfigurableModule {
@Override
public void configure(ConfigurableContext context) {
context.bind(GreetingService.class, DefaultGreetingService.class, "greetingService")
.scope(Scope.SINGLETON)
.usePostConstruct(service -> service.warmUp())
.usePreDestroy(service -> service.shutdown())
.usePostContainerInitialized(service -> service.onContainerReady());
context.bind(TimeProvider.class, SystemTimeProvider.class, "timeProvider")
.factory(SystemTimeProvider::new)
.scope(Scope.PROTOTYPE);
}
}
```
2. Add service registration file:
`src/main/resources/META-INF/services/io.abc.shared.di.ConfigurableModule`
with content:
```text
com.example.GreetingModule
```
3. Start the container:
```java
import io.abc.platform.container.pure.impl.ContainerRunner;
import io.abc.shared.di.AppContext;
public class Main {
public static void main(String[] args) {
AppContext context = ContainerRunner.start(args);
// GreetingModule is auto-loaded from META-INF/services
}
}
```
## Configuration and Conventions
Root Gradle and project configuration lives in:
- `settings.gradle.kts`
- `build.gradle.kts`
- `gradle.properties`
Core logging stack:
- API: `org.slf4j:slf4j-api`
- Backend: `ch.qos.logback:logback-classic`
- Config: `simple-di-core/src/main/resources/logback.xml`
## Roadmap
- Stabilize public API for a first tagged release.
- Expand usage examples and guides.
- Add compatibility matrix and benchmark notes.
- Improve publishing and release automation.
## Contributing
Contributions are welcome.
Suggested workflow:
1. Fork and create a feature branch.
2. Make focused changes with tests.
3. Run `./gradlew build` locally.
4. Open a pull request with a clear description.
When adding or changing behavior, include or update tests in `simple-di-core/src/test/java`.
## Code of Conduct
Please be respectful and constructive in all interactions.
See `CODE_OF_CONDUCT.md` for details.
## Security
If you discover a vulnerability, please report it privately to the maintainers instead of opening a public issue.
See `SECURITY.md` for reporting guidance.
## License
This project is licensed under the Apache License 2.0.
See `LICENSE` for details.