Skip to content

Toothpick ascii art

Stéphane Nicolas edited this page Jul 17, 2019 · 3 revisions

Toothpick wiki uses ascii art a lot to represent the scope tree.

This page summarizes the ascii art language we have developed. We suggest developers to use it as well for documentation purposes, questions on stack over flow, issues, etc.

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

       application = @RootScope          // a scope by the name 'application', 
          /             |   \            //bound to @RootScope (scope annotation)
         /              |    \  
        /               |     \
 @PresenterScope        |      \         //a scope by the name & bound to @PresenterScope
          /             |       \
         /              |      Service 2 // a scope by the name 'service 2'
        /            Service 1  
       /            
 Activity 1 : {Module 1, Module 2}       // a scope with 2 modules
    /   \
   /   Fragment 2 : Scope --> (fragment 2)  // a scoped binding of `Scope` to the instance `fragment 2`
  /
Fragment 1 : IFoo --> Foo                  //an unscoped binding of `IFoo` to `Foo`

Bindings can be represented graphically too :

//unscoped bindings
bind(Foo.class); // Foo --> Foo

//scoped bindings
bind(IFoo.class).to(Foo.class);  // IFoo --> (Foo)
bind(IFoo.class).to(Foo.class).singleton();  // IFoo --> (new Foo)
bind(IFoo.class).toInstance(new Foo()); //  IFoo --> (new Foo) or alternative above
bind(IFoo.class).toProvider(FooProvider.class); // IFoo --> (P<Foo>)
bind(IFoo.class).toProvider(FooProvider.class).singleton(); // IFoo --> (new P<Foo>)
bind(IFoo.class).toProvider(FooProvider.class).providesSingleton(); // IFoo --> (P<new Foo>)
bind(IFoo.class).toProviderInstance(new FooProvider()).providesSingleton().singleton() // IFoo --> (new P<new Foo>) or alternative above
bind(Foo.class); // Foo --> (Foo)
bind(Foo.class).singleton() // Foo --> (new Foo)