Skip to main content
Version: 0.1.1-a

Getting Started

Initialising Syringe​

Syringe's core is the Container. It is the central touchpoint for all interactions with Syringe.

There are two types of Container:

  • An ordinary Container
  • A global scope Container

Creating a global scope Container is the preferred way as it enables the use of the free DSL functions Syringe provides.

Creating a global scope Container:

import Syringe

class DependencyHandler {
init() {
injectSyringe {
modules {
// Modules go here
}
}
}
}

Creating Modules​

Modules are dependency lists in Syringe. Defining a module is simple:

let appModule = module {
// Dependencies go here
}

Adding Dependencies​

Adding dependencies to modules is done via the module DSL:

let appModule = module {
singleton { YourType() }
factory { Int.random(0..<5) }
}

Resolving Dependencies​

Resolving dependencies is done via either the module or application DSL:

class Service {
let value: Int

init(value: Int) {
self.value = value
}
}

let appModule = module {
// Resolving at module level
singleton { YourType(value: get()) }
factory { Int.random(0..<5) }
}

class View {
// Resolving at global level
let service: Service = get()

init() {

}
}
Additional resources
  • More about Container can be found here
  • More about Modules can be found here