To run the example project, clone the repo, and run pod install
from the Example directory first.
- Swift 5.5
EasyDependency is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'EasyDependency', '~> 3.0'
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.
- Register & retrieve dependencies from a DI container.
- Resolve list of implementations.
- Register dependencies as singletons.
- Added property wrappers for auto property injection.
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() }
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)
This concept is created together with Jelle Heemskerk (Github).
Niels Koole
EasyDependency is available under the MIT license. See the LICENSE file for more info.