Skip to content

Service

apleshkov edited this page Jul 30, 2018 · 8 revisions

Every service is a class or struct and can be attached to a needed container via scope (see the container section).

A service may depend on other services and its container can inject such dependencies via:

It's possible to mark an injection as "lazy" to its creation.

Also see about providers in case you don't "own" a class (e.g. it's a third-party class), but want to use it as a dependency.

All service annotations:

  • @saber.scope(ScopeName): associates a service with a corresponding container (only one container for each service).
  • @saber.cached: a "cached" service instance is reusable.
  • @saber.injectOnly: tells Saber to generate an injector only. It's useful if you don't control a service creation (e.g. view controllers from storyboards), but still want to inject dependencies there.
  • @saber.bindTo(TypeName): helps to make some dependencies abstract (more info in a corresponding section).
Clone this wiki locally