Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vanillasource/jaywire
JayWire Dependency Injection
https://github.com/vanillasource/jaywire
dependency-injection di java jaywire-dependency-injection
Last synced: 5 days ago
JSON representation
JayWire Dependency Injection
- Host: GitHub
- URL: https://github.com/vanillasource/jaywire
- Owner: vanillasource
- Created: 2015-02-07T15:59:43.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-02-21T02:56:18.000Z (over 1 year ago)
- Last Synced: 2024-08-01T18:24:50.269Z (3 months ago)
- Topics: dependency-injection, di, java, jaywire-dependency-injection
- Language: Java
- Homepage:
- Size: 263 KB
- Stars: 55
- Watchers: 7
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-java - JayWire - Lightweight dependency injection framework. (LGPL-3.0-only) (Projects / Dependency Injection)
- awesome-java-zh - JayWire - 轻量级的依赖注入框架。(LGPL-3.0-only) (项目 / 依赖注入)
- awesome-java - JayWire - Lightweight dependency injection framework. (LGPL-3.0-only) (Projects / Dependency Injection)
README
![Build Status](https://img.shields.io/travis/vanillasource/jaywire.svg)
![Published Version](https://img.shields.io/maven-central/v/com.vanillasource.jaywire/jaywire-parent.svg)
[![Join the chat at https://gitter.im/vanillasource/jaywire](https://badges.gitter.im/vanillasource/jaywire.svg)](https://gitter.im/vanillasource/jaywire?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)JayWire Dependency Injection
============================A very small and lightweight dependency injection framework for Java 8 without magic. Main features are:
* 100% pure Java code (no XML, no config files)
* Explicit, compile-time wireing
* Typesafe
* Modular and extendable
* Small and easyJayWire avoids any magic, that means:
* No classpath scanning
* No reflection
* No annotations
* No bytecode enhancement / weaving
* No transparent proxies
* No code generation
* No hidden / static state### Getting the library
Add this dependency to your Maven build:
```xml
com.vanillasource.jaywire
jaywire
1.1.0```
This will include the basic interfaces and scopes for standalone usage.
For integration with Web-frameworks see Wiki.### Wireing everything together
For a simple application a single "Module" object wireing everything together is written this way:
```java
import com.vanillasource.jaywire.standalone.StandaloneModule;public class MyAppModule extends StandaloneModule {
public Database getDatabase() {
return singleton(() -> new MyAppDatabase(...));
}public ServiceA getServiceA() {
return singleton(() -> new ServiceA(getDatabase()));
}public ServiceB getServiceB() {
return singleton(() -> new ServiceB(getDatabase(), getServiceA());
}
}
```In this example there is a Database, ServiceA and ServiceB, all of them singletons. It is assumed
that these services / classes are written in the usual Object-Oriented approach by taking all required
dependencies as constructor parameters.
These dependencies are then "injected" by simply calling the appropriate methods to get fully constructed
dependencies and supplying them as parameters to objects.You can use the _MyAppModule_ then at the "top" of your application to start processing:
```java
public class MyApp {
public static final void main(String[] argv) {
MyAppModule module = new MyAppModule();
module.getServiceB().run();
}
}
```### Documentation
The JayWire [API Documentation](http://vanillasource.github.io/jaywire/apidocs/).
Please visit the [JayWire Wiki](https://github.com/vanillasource/jaywire/wiki) for more information.
### Related external projects
* [Pouch](https://bitbucket.org/cowwoc/pouch/) is an interesting rethinking of the Service Locator pattern.