winter / io.jentz.winter / WinterApplication / <init>

<init>

WinterApplication(qualifier: Any = ApplicationScope::class, block: ComponentBuilderBlock)

Convenient constructor to configure the application Component during initialization.

Example:

object MyLibApp : WinterApplication {
  // ... declaration of dependencies
}

Parameters

qualifier - A qualifier for the component.

block - The component builder block.

WinterApplication()

Holds plugins, the application Component, the application Graph and offers an abstraction to inject dependencies into classes that cannot make use of constructor injection using an InjectionAdapter system.

The InjectionAdapter backed abstraction takes the burden off of the using class to know how exactly a graph or parent graph is constructed and stored.

An application specific graph creation and retrieval strategy can be provided by setting a custom InjectionAdapter.

Winter.adapter = MyCustomAdapter()

To use Winter in a library it is recommended to create a library specific object from WinterApplication for use in applications it is recommended to use the Winter object.

Example, using the SimpleAndroidInjectionAdapter which is part of the winter-androidx module:

class MyApplication : Application() {
  override fun onCreate() {
    super.onCreate()

    // register component
    Winter.component {
      singleton<GitHubApi> { GitHubApiImpl() }

      singleton { RepoListViewModel(instance()) }

      subcomponent("activity") {
         singleton { Glide.with(instance<Activity>()) }
      }
    }

    // register adapter
    Winter.useSimpleAndroidAdapter()
    // open application graph
    Winter.inject(this)
  }
}

class MyActivity : Activity(), WinterAware {
  private val viewModel: RepoListViewModel by inject()

  override fun onCreate(savedInstanceState: Bundle?) {
    Winter.inject(this)
    super.onCreate(savedInstanceState)
  }

}