Zurück zum Ranking

stephanenicolas/toothpick

Java

A scope tree based Dependency Injection (DI) library for Java / Kotlin / Android.

dependency-injectionandroidjavakotlinkotlin-androidandroidxandroid-viewmodelandroid-lifecycleandroid-testingandroid-dependency-injection
Sterne-Wachstum
Sterne
1.1k
Forks
113
Wochenwachstum
Issues
45
5001k
Apr. 2016Sept. 2019Feb. 2023Juli 2026
ArtefakteMavengit clone https://github.com/stephanenicolas/toothpick.git
README

Toothpick (a.k.a T.P. like a teepee)







Visit TP wiki !

What is Toothpick ?

Toothpick is a scope tree based Dependency Injection (DI) library for Java.

It is a full-featured, runtime based, but reflection free, implementation of JSR 330.

What does Toothpick offer ?

//a typical Toothpick scope tree during the execution of an Android app.

           @ApplicationScope 
             /          |    \  
            /           |     \
           /            |      \
   @ViewModelScope      |   Service 2
         /              | 
        /            Service 1  
       /            
 @Activity1Scope
      /
     /
Activity 1
   /   \
  /   Fragment 2
 /
Fragment 1

Scopes offer to compartmentalize memory during the runtime of an app and prevent memory leaks. All dependencies created via Toothpick, and available for injections, will be fully garbage collected when this scope is closed. To learn more about scopes, read TP wiki.

Toothpick is :

Examples

This is the example:

Setup

The latest version of TP is provided by a badge at the top of this page.

For Android :

#android setup using gradle 5.5.1
buildscript {
  repositories {
    google()
    jcenter()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.4.x'
  }
}

...
#for java
dependencies {
  implementation 'com.github.stephanenicolas.toothpick:toothpick-runtime:3.x'
  // and for android -> implementation 'com.github.stephanenicolas.toothpick:smoothie-androidx:3.x'
  annotationProcessor 'com.github.stephanenicolas.toothpick:toothpick-compiler:3.x'

  //highly recommended
  testImplementation 'com.github.stephanenicolas.toothpick:toothpick-testing-junit5:3.x'
  testImplementation 'mockito or easymock'
}

#for kotlin
dependencies {
  implementation 'com.github.stephanenicolas.toothpick:ktp:3.x'
  kapt 'com.github.stephanenicolas.toothpick:toothpick-compiler:3.x'

  //highly recommended
  testImplementation 'com.github.stephanenicolas.toothpick:toothpick-testing-junit5:3.x'
  testImplementation 'mockito or easymock'
}

For java:

<!--java setup with maven -->
  <dependencies>
    <dependency>
      <groupId>com.github.stephanenicolas.toothpick</groupId>
      <artifactId>toothpick-compiler</artifactId>
      <version>3.x</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.github.stephanenicolas.toothpick</groupId>
      <artifactId>toothpick-runtime</artifactId>
      <version>3.x</version>
      <scope>compile</scope>
    </dependency>
    
    <!-- highly recommended-->
    <dependency> 
      <groupId>com.github.stephanenicolas.toothpick</groupId>
      <artifactId>toothpick-testing</artifactId>
      <version>3.x</version>
      <scope>test</scope>
    </dependency>
    <dependency>
    <easymock or mockito>
    </dependency>
  </dependencies>

Support

TP is actively maintained and we provide support to questions via the Toothpick-di tag on Stack Over Flow.

Ask questions on Stack Over Flow while keeping the GitHub issue board for real issues. Thx in advance !

Talks & Articles

Wanna know more ?

Visit Toothpick's wiki !

Alternative Dependency Injection (DI) engines for Android

Libs / Apps using TP 2

  • Okuki is a simple, hierarchical navigation bus and back stack for Android, with optional Rx bindings, and Toothpick DI integration.
  • KotlinWeather is a simple example of using ToothPick with Kotlin and gradle integration using kapt.

Credits

TP 1 & 3 have been developped by Stephane Nicolas and Daniel Molinero Reguera. Most of the effort on version 2 has been actively supported by Groupon. Thanks for this awesome OSS commitment !

Ähnliche Repositories
kataras/iris

The fastest HTTP/2 Go Web Framework. New, modern and easy to learn. Fast development with Code you control. Unbeatable cost-performance ratio :rocket:

GoGo ModulesBSD 3-Clause "New" or "Revised" Licensegoiris
iris-go.com
25.6k2.4k
Effect-TS/effect

Build production-ready applications in TypeScript

TypeScriptnpmMIT Licenseeffectjavascript
effect.website
15k620
alibaba/ARouter

💪 A framework for assisting in the renovation of Android componentization (帮助 Android App 进行组件化改造的路由框架)

JavaMavenApache License 2.0androidrouter
14.5k2.6k
google/wire

Compile-time Dependency Injection for Go

GoGo ModulesApache License 2.0gogolang
14.4k745
inversify/InversifyJS

Powerful and lightweight inversion of control container. Moved to https://github.com/inversify/monorepo

TypeScriptnpmMIT Licensetypescriptioc
inversify.io
12.1k711
jonataslaw/getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.

DartMIT Licensegetxdependency-injection
11.2k1.9k
InsertKoinIO/koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform

KotlinApache License 2.0kotlindependency-injection
insert-koin.io
10k786
evrone/go-clean-template

Clean Architecture template for Golang services

GoGo ModulesMIT Licenseclean-architecturego
7.6k658
uber-go/fx

A dependency injection based application framework for Go.

GoGo ModulesMIT Licensegolanggo
uber-go.github.io/fx/
7.6k346
hyperf/hyperf

🚀 A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.

PHPPackagistMIT Licenseswoolecoroutine
hyperf.io
6.9k1.3k
Swinject/Swinject

Dependency injection framework for Swift with iOS/macOS/Linux

SwiftMIT Licensedependency-injectiondi-container
6.7k543
microsoft/tsyringe

Lightweight dependency injection container for JavaScript/TypeScript

TypeScriptnpmMIT Licensedependency-injectiondependency
6k182