{"id":3222,"url":"https://github.com/ladeiko/ViperServices","last_synced_at":"2025-08-03T13:32:20.875Z","repository":{"id":56926056,"uuid":"132002906","full_name":"ladeiko/ViperServices","owner":"ladeiko","description":"Simple dependency injection container for services written for iOS in swift supporting boot order","archived":false,"fork":false,"pushed_at":"2023-03-30T06:30:41.000Z","size":107,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-10T03:37:29.622Z","etag":null,"topics":["dependency-injection","ios","service-container","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ladeiko.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-05-03T13:56:53.000Z","updated_at":"2024-03-19T21:58:57.000Z","dependencies_parsed_at":"2024-01-02T21:28:47.580Z","dependency_job_id":null,"html_url":"https://github.com/ladeiko/ViperServices","commit_stats":{"total_commits":29,"total_committers":3,"mean_commits":9.666666666666666,"dds":"0.27586206896551724","last_synced_commit":"bd8602000ded63069c82df1ff276a1c59a126dbe"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladeiko%2FViperServices","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladeiko%2FViperServices/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladeiko%2FViperServices/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladeiko%2FViperServices/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ladeiko","download_url":"https://codeload.github.com/ladeiko/ViperServices/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228548567,"owners_count":17935221,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dependency-injection","ios","service-container","swift"],"created_at":"2024-01-05T20:16:34.919Z","updated_at":"2024-12-07T01:30:44.375Z","avatar_url":"https://github.com/ladeiko.png","language":"Swift","funding_links":[],"categories":["Dependency Injection"],"sub_categories":["Getting Started","Web View"],"readme":"# ViperServices\n\n[![Platform](https://img.shields.io/badge/Platform-iOS-lightgrey.svg?colorA=28a745\u0026colorB=4E4E4E)](https://img.shields.io/badge/Platform-iOS-lightgrey.svg?colorA=28a745\u0026colorB=4E4E4E)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/ViperServices.svg?style=flat\u0026label=CocoaPods\u0026colorA=28a745\u0026\u0026colorB=4E4E4E)](https://cocoapods.org/pods/ViperServices)\n[![Swift support](https://img.shields.io/badge/Swift-4.0%20%7C%204.1%20%7C%204.2%20%7C%205.0-lightgrey.svg?colorA=28a745\u0026colorB=4E4E4E)](#swift-versions-support)\n[![Build Status](https://travis-ci.org/ladeiko/ViperServices.svg?branch=master)](https://travis-ci.org/ladeiko/ViperServices)\n\n## Introduction\nViperServices is dependency injection container for iOS applications written in Swift.\nIt is more lightweight and simple in use than:\n\n* [Kraken](https://github.com/sabirvirtuoso/Kraken)\n* [Guise](https://github.com/prosumma/Guise)\n* etc.\n\nAlso it introduces 'bootable' concept of service. Also services can define units they depends on.\n\n## Changelog\n\nSee [CHANGELOG](CHANGELOG.md)\n\n## Installation\n\n### Cocoapods\n\u003e This is the recommended way of installing this package.\n\n* Add the following line to your Podfile\n\n``` ruby\npod 'ViperServices'\n```\n* Run the following command to fetch and build your dependencies\n\n``` bash\npod install\n```\n\n### Manually\nIf you prefer to install this package manually, just follow these steps:\n\n* Make sure your project is a git repository. If it isn't, just run this command from your project root folder:\n\n``` bash\ngit init\n```\n\n* Add ViperServices as a git submodule by running the following command.\n\n``` bash\ngit submodules add https://github.com/ladeiko/ViperServices.git\n```\n* Add files from *'submodules/ViperServices/Sources'* folder to your project.\n\n## Usage\n\n* Define your viper services:\n\n``` swift\nimport ViperServices\n\nprotocol Service1: AnyObject {\n    func foo()\n}\n\nclass Service1Impl: Service1, ViperService {\n    \n    func setupDependencies(_ container: ViperServicesContainer) -\u003e [AnyObject]? {\n        return [ // depends on\n            container.resolve() as Service2\n        ]\n    }\n    \n    func boot(launchOptions: [UIApplication.LaunchOptionsKey : Any]?, completion: @escaping ViperServiceBootCompletion) {\n        print(\"boot 1 called\")\n        completion(.succeeded) // sync completion\n    }\n    \n    func foo() {\n        print(\"foo 1 called\")\n    }\n    \n}\n\nprotocol Service2: AnyObject {\n    func foo()\n}\n\nenum Service2Error: Error {\n    case SomeError\n}\n\nclass Service2Impl: Service2, ViperService {\n    \n    private weak var container: ViperServicesContainer!\n    \n    func setupDependencies(_ container: ViperServicesContainer) -\u003e [AnyObject]? {\n        self.container = container\n        return nil\n    }\n    \n    func boot(launchOptions: [UIApplication.LaunchOptionsKey : Any]?, completion: @escaping ViperServiceBootCompletion) {\n        print(\"boot 2 called\")\n        DispatchQueue.main.asyncAfter(deadline: .now() + 3) { // async completion\n            switch arc4random() % 2 { // emulate random result\n            case 0:\n                completion(.failed(error: Service2Error.SomeError))\n            default:\n                completion(.succeeded)\n            }\n            \n        }\n    }\n    \n    func foo() {\n        print(\"foo 2 called\")\n    }\n    \n}\n```\n\n* Add following code to application delegate:\n\n``` swift\nvar window: UIWindow?\n\n// use DefaultViperServicesContainer or implement your own container\nlet services = DefaultViperServicesContainer() \n\nfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -\u003e Bool {\n    // Override point for customization after application launch.\n    \n    try! services.register(Service1Impl() as Service1)\n    try! services.register(Service2Impl() as Service2)\n    \n    services.boot(launchOptions: launchOptions) { (result) in\n        switch result {\n        case .succeeded:\n            // All ok, now it is safe to use any service!\n            (self.services.resolve() as Service1).foo()\n            (self.services.resolve() as Service2).foo()\n            \n        case let .failed(failedServices):\n            // Boot failed, show error to user\n            let alert = UIAlertController(title: \"Error\",\n                                      message: failedServices.first!.error.localizedDescription,\n                                      preferredStyle: .alert)\n            alert.addAction(UIAlertAction(title: \"OK\", style: .default, handler: nil))\n            self.window!.rootViewController?.present(alert, animated: false, completion: nil)\n        }\n    }\n    \n    return true\n}\n```\n\n\n## LICENSE\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladeiko%2FViperServices","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fladeiko%2FViperServices","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladeiko%2FViperServices/lists"}