• Stars
    star
    1,123
  • Rank 41,432 (Top 0.9 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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 !

More Repositories

1

robospice

Repo of the Open Source Android library : RoboSpice. RoboSpice is a modular android library that makes writing asynchronous long running tasks easy. It is specialized in network requests, supports caching and offers REST requests out-of-the box using extension modules.
Java
2,946
star
2

Quality-Tools-for-Android

Java
1,266
star
3

boundbox

BoundBox provides an easy way to test an object by accessing all its fields, constructor and methods, public or not. BoundBox breaks encapsulation.
Java
229
star
4

RoboDemo

RoboDemo is a ShowCase library for Android to demonstrate to users how a given Activity works.
Java
215
star
5

loglifecycle

Logs all lifecycle methods of annotated Activities, Fragments, Services, Views, etc.
Java
206
star
6

reflection-no-reflection

A proof on concept to create an API that is 100% compatible reflection API, but without any reflection. Performance stuff for Android and Java.
Java
130
star
7

ormlite-android-gradle-plugin

A Gradle plugin for Android to generate an ORMLite configuration file and boost DAOs creations.
Java
102
star
8

morpheus

An Android gradle plugin to transform classes via javassist.
Java
80
star
9

afterburner

A library to help other librairies getting rid of boiler plate via byte code manipulation. Works on Android too.
Java
74
star
10

injectextra

Injects everything passed by extra to an activity automatically.
Java
26
star
11

androidstudio4maccheatsheet

Most useful keyboard shortcuts with default keymap in Android Studio.
23
star
12

mimic

Mimicing is, indeed, kind of way to bypass java single inheritance paradigm. It allows to copy all declared fields, constructors and methods in a given class into another class.
Java
19
star
13

activtity-fragment-lambda

Example of how to use lambdas to communicate between Fragments and Activities
Java
17
star
14

injectview

On Android, Injects all views inflated from XML automatically. No boiler plate at all.
Java
17
star
15

injects

This repo is a control center for the injects projects.
9
star
16

injectresource

Inject resources automatically on Android.
Java
8
star
17

javassist-build-plugin-api

A unified API to create class transformers based on javassist during maven and gradle builds.
Java
7
star
18

TypedAdapter

Object Oriented android list view adapter(s) using generics to display given Pojos.
Java
5
star
19

google-guice

A fork of Google Guice to allow RoboGuice to go faster at startup.
Java
3
star
20

zest-android

Sample app to demonstrate roboguice usage + testing
Java
3
star
21

Dependency-Resources-Linearization

Demonstrate that the linearization of the dependency graph that gives to the order of priority to aapt2 when merging resources is hard to grasp for humans and that we can quickly have problems when scaling the number of modules.
Kotlin
3
star
22

MixedServiceLifeCycle-sample

A sample to demonstrate that a mixed life cycle service (both started and bound) is buggy. Built for a common guy ;)
Java
2
star
23

heatControl

Controls a custom micro controller on a heating system
Kotlin
1
star
24

bugs-instant-execution

Sample project to illustrate instant execution bugs in Android projects
Shell
1
star