toothpick-runtime / toothpick / Toothpick

Toothpick

open class Toothpick

Main class to access toothpick features. It allows to create / retrieve scopes and perform injections.

The main rule about using TP is : TP will honor all injections in the instances it creates by itself. A soon as you use new Foo, in a provider or a binding for instance, TP is not responsible for injecting Foo; developers have to manually inject the instances they create.

Functions

closeScope

open static fun closeScope(name: Any): Unit

Detach a scope from its parent, this will trigger the garbage collection of this scope and it's sub-scopes if they are not referenced outside of Toothpick.

inject

open static fun inject(obj: Any, scope: Scope): Unit

Injects all dependencies (transitively) in obj, dependencies will be obtained in the scope scope.

isScopeOpen

open static fun isScopeOpen(name: Any): Boolean

Indicates whether a scope is open.

openRootScope

open static fun openRootScope(): Scope

Returns or opens a root scope as follows:

  • if there's an existing scope tree the root scope of that tree;
  • creates a default root scope if there's none;
  • throws an exception if there are multiple scope trees (e.g. a forest);

openScope

open static fun openScope(name: Any): Scope

Opens a scope without any parent. If a scope by this name already exists, it is returned. Otherwise a new scope is created.

open static fun openScope(name: Any, scopeConfig: ScopeConfig): Scope

Opens a scope without any parent. If a scope by this name already exists, it is returned. Otherwise a new scope is created. If a new scope is created, then scopeConfig is applied to the new scope.

openScopes

open static fun openScopes(vararg names: Any): Scope

Opens multiple scopes in a row. Opened scopes will be children of each other in left to right order (e.g. openScopes(a,b) opens scopes a and b and b is a child of a.

release

open static fun release(scope: Scope): Unit

Resets the state of a single scope. Useful for automation testing when we want to reset the scope used to install test modules.

reset

open static fun reset(): Unit

Clears all scopes. Useful for testing and not getting any leak...

open static fun reset(scope: Scope): Unit

Resets the state of a single scope. Useful for automation testing when we want to reset the scope used to install test modules.

setConfiguration

open static fun setConfiguration(configuration: Configuration): Unit

Allows to pass custom configurations.