Swiftpack.co -  BrickmakersGmbH/swift-ioc-container as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
BrickmakersGmbH/swift-ioc-container
Swift-IoC-Container is a tool with an easy to use API. It automatically resolves dependencies
.package(url: "https://github.com/BrickmakersGmbH/swift-ioc-container.git", from: "0.3.3")

swift-ioc-container

Actions Status Actions Status

import Swift_IoC_Container

protocol SuperAwesomeBot {
    func saySomething()
}

class StarWarsBot: SuperAwesomeBot {
    func saySomething() {
        print("The Force will be with you. Always.")
    }
}

And use it like this:

// only needed once
IoC.shared.registerLazySingleton(SuperAwesomeBot.self, { StarWarsBot() }) 


let myBot: SuperAwesomeBot = try! IoC.shared.resolve()
myBot.saySomething()

If you are using Swift 5.1 or newer, you could take advantage of the new property wrapper feature. It's already implemented in this library.

There is no more need to initialize the property manually in the initializer. Just declare the property with the expected protocol type.

@Injected private var myBot: SuperAwesomeBot

After declaring the property as @Injected you can access the previously registered object as you are used to.

An example implementation can be found in Example.swift

Requirements

There are no further requirements beside Swift 5.1, just copy this little lib in your project and start.

Installation

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

pod 'Swift-IOC-Container'

Updating

  1. First, do your changes :)
  2. Update PodSpec with a new version number
  3. Push and create a new tag with the same version number
  4. Execute the following line to update PodSpec on CocoaPods.org
pod trunk push Swift-IOC-Container.podspec

Note:

You need to be an owner of course.

  • Create your account like this:
pod trunk register myEmail@mail.de "Mein Name" --description="Name meines Rechners"
  • An owner needs to add you as owner:
pod trunk add-owner Swift-IOC-Container email@email.de

Troubleshooting:

Error with .netRc:

chmod 0600 ~/.netrc

Authors

Michael Scherbakow, michael.scherbakow@brickmakers.de
Jonas Österle, jonas.oesterle@brickmakers.de
Pascal Friedrich, pascal.friedrich@brickmakers.de
Philipp Manstein, philipp.manstein@brickmakers.de

License

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

GitHub

link
Stars: 14
Last commit: 6 days ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Dependencies

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API