All Projects → ljacqu → DependencyInjector

ljacqu / DependencyInjector

Licence: MIT license
Lightweight dependency injector

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to DependencyInjector

Poodinis
A dependency injection framework for D with support for autowiring.
Stars: ✭ 57 (+90%)
Mutual labels:  ioc, dependency-injection, injection, ioc-container
Reflex
Minimal dependency injection framework for Unity
Stars: ✭ 263 (+776.67%)
Mutual labels:  ioc, dependency-injection, injection, ioc-container
React Ioc
Hierarchical Dependency Injection with new React 16 Context API
Stars: ✭ 133 (+343.33%)
Mutual labels:  ioc, dependency-injection, injection, ioc-container
Container Ioc
Inversion of Control container & Dependency Injection for Javascript and Node.js apps powered by Typescript.
Stars: ✭ 89 (+196.67%)
Mutual labels:  ioc, dependency-injection, injection, dependency
Zenject-2019
Dependency Injection Framework for Unity3D
Stars: ✭ 2,567 (+8456.67%)
Mutual labels:  ioc, dependency-injection, injection, dependency
vesselize
⛵ A JavaScript IoC container that works seamlessly with Vue.js and React.
Stars: ✭ 22 (-26.67%)
Mutual labels:  ioc, dependency-injection, injection, ioc-container
inject
[Archived] See https://github.com/goava/di.
Stars: ✭ 49 (+63.33%)
Mutual labels:  ioc, dependency-injection, ioc-container, injector
Kangaru
🦘 A dependency injection container for C++11, C++14 and later
Stars: ✭ 297 (+890%)
Mutual labels:  ioc, dependency-injection, injection, ioc-container
Tsyringe
Lightweight dependency injection container for JavaScript/TypeScript
Stars: ✭ 2,761 (+9103.33%)
Mutual labels:  ioc, dependency-injection, injection, dependency
di
🛠 A full-featured dependency injection container for go programming language.
Stars: ✭ 156 (+420%)
Mutual labels:  ioc, dependency-injection, ioc-container
Disco
PSR-11 compatible Dependency Injection Container for PHP.
Stars: ✭ 135 (+350%)
Mutual labels:  ioc, dependency-injection, ioc-container
iocgo
A lightweight Inversion of Control (IoC) (Dependency Injection) container for Golang
Stars: ✭ 36 (+20%)
Mutual labels:  ioc, dependency-injection, ioc-container
Node Dependency Injection
The NodeDependencyInjection component allows you to standarize and centralize the way objects are constructed in your application.
Stars: ✭ 140 (+366.67%)
Mutual labels:  ioc, dependency-injection, ioc-container
Container
A lightweight yet powerful IoC container for Go projects
Stars: ✭ 160 (+433.33%)
Mutual labels:  ioc, dependency-injection, ioc-container
tsdi
Dependency Injection container (IoC) for TypeScript
Stars: ✭ 50 (+66.67%)
Mutual labels:  ioc, dependency-injection, injection
Python Dependency Injector
Dependency injection framework for Python
Stars: ✭ 1,203 (+3910%)
Mutual labels:  ioc, dependency-injection, ioc-container
Typhoon
Powerful dependency injection for Objective-C ✨✨ (https://PILGRIM.PH is the pure Swift successor to Typhoon!!)✨✨
Stars: ✭ 2,711 (+8936.67%)
Mutual labels:  ioc, dependency-injection, ioc-container
Ioc
🦄 lightweight (<1kb) inversion of control javascript library for dependency injection written in typescript
Stars: ✭ 171 (+470%)
Mutual labels:  ioc, dependency-injection, ioc-container
SwiftInjection
Dependency Injection framework for Swift
Stars: ✭ 21 (-30%)
Mutual labels:  ioc, dependency-injection, ioc-container
Singularity
A extremely fast ioc container for high performance applications
Stars: ✭ 63 (+110%)
Mutual labels:  ioc, dependency-injection, ioc-container

Lightweight Dependency Injector

Build Status Coverage Status Javadocs Code Climate

Simple but customizable dependency injector for Java 1.8 and above.

Why use it

  • Very lightweight (only has javax.inject and javax.annotation-api as dependency)
  • Allows gradual transition to injection for existing projects
  • You can implement your own injection methods and behaviors
  • Support for projects with optional dependencies

Integrating it

Using Maven, you can get the injector by adding this to your pom.xml:

<dependency>
    <groupId>ch.jalu</groupId>
    <artifactId>injector</artifactId>
    <version>1.0</version>
</dependency>

Simple example

By default, the injector supports constructor injection and field injection. Consider the following class skeletons:

public class Settings {
  // regular class
}

public class Messages {
  private File messagesFile;

  @Inject
  Messages(Settings settings) {
    messagesFile = new File(settings.getLanguage() + ".txt");
  }
}

public class CalculationService {
  @Inject
  private Messages messages;
  
  @Inject
  private RoundingService roundingService;
}

public class RoundingService {
  private int precision;

  @Inject
  RoundingService(Settings settings) {
    precision = settings.getPrecision();
  }
}

At the startup of the application, we might only care about getting an instance of CalculationService. All other classes are required by it to run, but we don't immediately care about them. With the injector, we don't have to deal with those classes and can just retrieve what we actually want:

public class MyApp {

  public static void main(String... args) {
    Injector injector = new InjectorBuilder().addDefaultHandlers("com.example.my.project").create();
    CalculationService calcService = injector.getSingleton(CalculationService.class);
    calcService.performCalculation();
  }
}

... That's all! No need to deal with creating any other classes, but you still have a setup that allows you to easily unit test or switch a component.

--> Full, runnable example can be found here.

Handlers

You may implement your own logic to instantiate classes and resolve dependencies. This allows you, for example, to implement specific behavior for custom annotations. Read more on the Wiki: Handlers explained

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].