winter / io.jentz.winter / WinterTree

WinterTree

open class WinterTree

WinterTree acts as an holder for the application object graph and is a helper for opening, closing and accessing subgraphs by paths of identifiers.

Instances of WinterTree are usually not used directly but in injection adapters.

This is inspired by Toothpicks openScope/closeScope mechanism, if you like that, you can simply use GraphRegistry instead of the Injection abstraction.

Example:

// register the application component
Winter.component {
  // ... the component definition
}
val tree = WinterTree(Winter)

// open the application graph
tree.open()
// or supply a builder block to extend the resulting graph
tree.open { constant<Application>(myApplication) }

// the application graph can then be accessed by calling
tree.get()

// to open a subgraph call
tree.open("subcomponent qualifier")

// this graph can be accessed by calling
tree.get("subcomponent qualifier")

// you can provide an optional identifier for the subgraph
tree.open("subcomponent qualifier", identifier = "other name")

// then you can access the the subgraph by calling
tree.get("other name")

// to open a subgraph of this call
tree.open("subcomponent qualifier", "sub-subcomponent qualifier")
// respectively
tree.open("other name", "sub-subcomponent qualifier")

Constructors

<init>

WinterTree(application: WinterApplication)

WinterTree acts as an holder for the application object graph and is a helper for opening, closing and accessing subgraphs by paths of identifiers.

Functions

close

fun close(vararg path: Any): Unit

Remove and dispose the object graph and its subgraphs stored in path.

closeIfOpen

fun closeIfOpen(vararg path: Any): Boolean

Remove and dispose the object graph and its subgraphs stored in path if it is open.

create

fun create(vararg path: Any, block: ComponentBuilderBlock? = null): Graph

Create and return an object graph by (sub-)component path without registering it.

get

fun get(vararg path: Any): Graph

Get a registered object graph by path.

has

fun has(vararg path: Any): Boolean

Returns true if an entry under the given path exists otherwise false.

open

fun open(vararg path: Any, identifier: Any? = null, block: ComponentBuilderBlock? = null): Graph

Create a object graph by (sub-)component path and register it. Opened object graphs will be children of each other in left to right order.

Inheritors

GraphRegistry

object GraphRegistry : WinterTree

An object version of WinterTree that uses Winter as its WinterApplication.