EasyDependency 3.0.6

EasyDependency 3.0.6

Maintained by Niels Koole.



EasyDependency

CI Status Version License Platform Twitter

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • Swift 5.1

Installation

EasyDependency is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'EasyDependency', '~> 3.0'

Summary

EasyDependency is a very lightweight dependency injection framework, without magic. Just a container to register and resolve dependencies. There is no focus on adding support for circular dependencies or automatic injection of dependencies. Simplicity is key.

Features

  • Register & retrieve dependencies from a DI container.
  • Resolve list of implementations.
  • Register dependencies as singletons.
  • Added property wrappers for auto property injection.

Usage

Register a dependency

This way you register an implementation on a protocol.

try DISharedContainer.register(Storage.self) { _ in StorageAImpl() }
try DISharedContainer.register(Storage.self) { _ in StorageBImpl() }
try DISharedContainer.register(Storage.self, .lazySingleton) { _ in StorageBImpl() }

Retrieve a dependency

You can retrieve the implementation by resolve the dependency by its interface.

let storage: Storage = try appContainer.resolve()
let storageList: [Storage] = try appContainer.resolve()
let storage: Storage? = try? (appContainer.resolve() as Storage)

Credits

This concept is created together with Jelle Heemskerk (Github).

Author

Niels Koole

License

EasyDependency is available under the MIT license. See the LICENSE file for more info.