View on GitHub

Alchemic v2.1

An advanced DI framework for iOS

Carthage compatible

API: Objective-C Swift 3

HomeInstallationAdding AlchemicArchitectureObject factoriesInjectionsValue typesProgrammatic usageiOS featuresAdvanced usageError handlingReference

How Alchemic works

The following are the main architectural items that you will come across when working with Alchemic.

The context

Every interaction with Alchemic takes place through the Alchemic context. Implementing the ALCContext protocol, the context is essentially a self starting singleton instance that contains all the methods needed to tell Alchemic about your app. The context is also responsible for starting Alchemic, resolving dependencies, performing injections and a bunch of other things.

The data model

Behind the context, Alchemic maintains an in memory data model. It’s where Alchemic stores all the your app’s setup. When starting up, Alchemic scans your project and executes any setup methods it finds to create this model. This is known as the registration phase of Alchemic’s startup process.

Object factories

The data model contains a collection of Object factories. These describe what sort of object you want them to manage and the dependencies they have. Object factories can manage singleton instances, factories (AKA Templates) and references to externally created objects such as UIViewControllers. Object factories are usually created automatically during registration.

Alchemic’s boot sequence

Alchemic will automatically start itself when your application loads. It follows this logic:

  1. Self starts on a background thread so that your application’s startup is not impacted.
  2. Registration phase: Scans all classes in your app for dependency injection declarations and executes them to setup the model.
  3. Resolving phase: Resolves all references and configures the internal model based on the found declarations.
  4. Singletons phase: Instantiates any classes declared as Singletons and wires up their dependencies.
  5. Post the “AlchemicFinishedLoading” notification.