Ultra-lightweight dependency injection for Java.
Minimal overhead, annotation-driven, zero config.
- Lightweight – tiny footprint, fast startup, no XML config
- Annotation-driven –
@Component,@Wired,@Named,@PreDestroy - Automatic resolution – scans classpath, resolves graphs, handles cycles
- Constructor & field injection –
@Wiredon fields or constructor params - Method components –
@Componenton factory methods for programmatic wiring - Shutdown hooks – automatic
@PreDestroycleanup via runtime hook
Add dependency (Maven Central):
<dependency>
<groupId>dev.pixelib.needle</groupId>
<artifactId>needle</artifactId>
<version>1.1.0</version>
</dependency>public class App {
static void main(String[] args) {
Needle needle = Needle.init(App.class);
}
}More examples
@Component
public class ExampleService {
@Wired
private Database db;
}@Component
@Named("main")
public class MainDatabase implements Database { }
@Component
@Named("backup")
public class BackupDatabase implements Database { }@Component
public class AppConfig {
@Component
Database createDatabase() {
return new Database("jdbc:...");
}
}@Component
public class OrderService {
private final PaymentGateway gateway;
public OrderService(PaymentGateway gateway) {
this.gateway = gateway;
}
}- Java 21+
mvn clean testJaCoCo coverage report generated at target/site/jacoco/index.html.
PRs welcome. Keep it lightweight.
GNU General Public License v3.0 — see LICENSE.