Latest 1.0.9
Homepage https://github.com/viniciusaro/SwiftResolver
License MIT
Platforms ios 8.0, osx 10.9, tvos 9.0, watchos 2.0, requires ARC
Authors

Dependency injection framework for Swift.

Usage

container.register { MyService() as Service }
...
let service: Service = container.resolve()

You can find more detailed use cases in the wiki page

Instalation

pod 'SwiftResolver'

Multiple Implementations of same Protocol

You can register multiple implementations of the same protocol in the same container.
Later, when resolving, the specific type of the implementation can be passed as parameter to obtain the correct implementation type.

container.register(MyService.init).as(ServiceProtocol.self)
container.register(OtherService.init).as(ServiceProtocol.self)
...
let service: ServiceProtocol = container.resolve(MyService.self) // instance of MyService is returned here

Multiple Configurations

You can register multiple implementations of the same object with different configurations.
Later, when resolving, an identifier of the implementation can be passed as parameter to obtain the correct implementation type.

enum MyServices: String {
    case mock
    case live
}

container.register { MyService(requestProvider: liveRequestProvider) }.tag(MyServices.live)
container.register { MyService(requestProvider: mockRequestProvider) }.tag(MyServices.mock)
...
let service: Service = container.resolve(MyServices.live)

Thread Safety

SwiftResolver is thread safe. This means you can register/resolve in different threads.

However, this is not a good practice since resolving instances that are not registered yet results in a fatalError.

Using an AppContainer as described in the wiki page, with a one time registration process that happens in the application start is recommended.

References

Latest podspec

{
    "name": "SwiftResolver",
    "version": "1.0.9",
    "summary": "Dependency injection framework for Swift.",
    "description": "The dependency injection pattern helps your app split into loosely-coupled components,nwhich can be developed, tested and maintained more easily. SwiftResolver helps younachieve that in an organized way.",
    "homepage": "https://github.com/viniciusaro/SwiftResolver",
    "license": "MIT",
    "authors": {
        "Vinicius Rodrigues": "[email protected]"
    },
    "source": {
        "git": "https://github.com/viniciusaro/SwiftResolver.git",
        "tag": "1.0.9"
    },
    "social_media_url": "https://twitter.com/vinizzera",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "requires_arc": true,
    "source_files": "Sources/**/*.swift"
}

Pin It on Pinterest

Share This