Skip to content

avdyushin/Injected

Repository files navigation

Injected

Dependency Injection using Swift Property Wrappers

How to use?

Define dependencies (e.g. in AppDelegate) that need to be injected via property:

let dependencies = Dependencies {
    Dependency { LocationService() }
    Dependency { StorageService() }
    // ...
}

Build when it's needed (e.g. in Scene willConnectTo):

dependencies.build()

Define injected properties:

@Injected var location: LocationService
@Injected var storage: StorageService

Iterate over all dependencies:

for service in dependencies {
    service.start()
}

Access using dynamic member lookup:

let location: LocationProtocol? = dependencies.locationService // Erase type to protocol
let storage: StorageService = dependencies.storageService! // Force unwarp if needed

More details on implementation and usage is here

How to add it to Xcode project?

  1. In Xcode select File ⭢ Swift Packages ⭢ Add Package Dependency...
  2. Copy-paste repository URL: https://github.com/avdyushin/Injected
  3. Hit Next two times, under Add to Target select your build target.
  4. Hit Finish

About

Dependency Injection Framework

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages