Skip to content

pixelib/Needle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Needle

Needle

Maven Central CI Coverage Java 21 License

Ultra-lightweight dependency injection for Java.
Minimal overhead, annotation-driven, zero config.


Features

  • 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@Wired on fields or constructor params
  • Method components@Component on factory methods for programmatic wiring
  • Shutdown hooks – automatic @PreDestroy cleanup via runtime hook

Getting Started

Install

Add dependency (Maven Central):

<dependency>
    <groupId>dev.pixelib.needle</groupId>
    <artifactId>needle</artifactId>
    <version>1.1.0</version>
</dependency>

Quick start

public class App {
    static void main(String[] args) {
        Needle needle = Needle.init(App.class);
    }
}

More examples

Component classes

@Component
public class ExampleService {
    @Wired
    private Database db;
}

Named components

@Component
@Named("main")
public class MainDatabase implements Database { }

@Component
@Named("backup")
public class BackupDatabase implements Database { }

Factory / method components

@Component
public class AppConfig {
    @Component
    Database createDatabase() {
        return new Database("jdbc:...");
    }
}

Constructor injection

@Component
public class OrderService {
    private final PaymentGateway gateway;

    public OrderService(PaymentGateway gateway) {
        this.gateway = gateway;
    }
}

Requirements

  • Java 21+

Build

mvn clean test

JaCoCo coverage report generated at target/site/jacoco/index.html.

Contributing

PRs welcome. Keep it lightweight.

License

GNU General Public License v3.0 — see LICENSE.

About

A ultra lightweight dependency injection framework like Spring

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages