{"id":3223,"url":"https://github.com/ivlevAstef/DITranquillity","last_synced_at":"2025-08-03T13:32:20.376Z","repository":{"id":43946190,"uuid":"60842718","full_name":"ivlevAstef/DITranquillity","owner":"ivlevAstef","description":"Dependency injection for iOS (Swift)","archived":false,"fork":false,"pushed_at":"2023-09-07T11:15:43.000Z","size":4028,"stargazers_count":414,"open_issues_count":12,"forks_count":32,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-04-14T19:10:10.792Z","etag":null,"topics":["dependency-injection","di","di-container","inversion-of-control","ioc","ios","swift"],"latest_commit_sha":null,"homepage":null,"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/ivlevAstef.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,"dei":null}},"created_at":"2016-06-10T11:20:39.000Z","updated_at":"2024-05-30T17:00:57.129Z","dependencies_parsed_at":"2024-04-24T18:58:40.561Z","dependency_job_id":null,"html_url":"https://github.com/ivlevAstef/DITranquillity","commit_stats":{"total_commits":672,"total_committers":7,"mean_commits":96.0,"dds":"0.14136904761904767","last_synced_commit":"1df9731f7434d706df718322d58f28d669242335"},"previous_names":[],"tags_count":112,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivlevAstef%2FDITranquillity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivlevAstef%2FDITranquillity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivlevAstef%2FDITranquillity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivlevAstef%2FDITranquillity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivlevAstef","download_url":"https://codeload.github.com/ivlevAstef/DITranquillity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227298821,"owners_count":17760384,"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","di","di-container","inversion-of-control","ioc","ios","swift"],"created_at":"2024-01-05T20:16:34.945Z","updated_at":"2025-08-03T13:32:20.357Z","avatar_url":"https://github.com/ivlevAstef.png","language":"Swift","funding_links":[],"categories":["Dependency Injection"],"sub_categories":["Getting Started","Web View"],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src =\"https://habrastorage.org/files/c6d/c89/5d0/c6dc895d02324b96bc679f41228ab6bf.png\" alt=\"Tranquillity\"/\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003ca href=\"http://cocoapods.org/pods/DITranquillity\"\u003e\u003cimg src =\"https://img.shields.io/cocoapods/v/DITranquillity.svg?style=flat\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\u003cimg src =\"https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://swift.org/package-manager\"\u003e\u003cimg src =\"https://img.shields.io/badge/SwiftPM-compatible-4BC51D.svg?style=flat\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/ivlevAstef/DITranquillity/blob/master/LICENSE\"\u003e\u003cimg src =\"https://img.shields.io/github/license/ivlevAstef/DITranquillity.svg?maxAge=2592000\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://developer.apple.com/swift\"\u003e\u003cimg src =\"https://img.shields.io/badge/Swift-3.0--6.0-F16D39.svg?style=flat\"/\u003e\u003c/a\u003e\n\u003ca href=\"http://cocoapods.org/pods/DITranquillity\"\u003e\u003cimg src =\"https://img.shields.io/badge/platform-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS%20%7C%20Linux-lightgrey.svg\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/ivlevAstef/DITranquillity\"\u003e\u003cimg src =\"https://codecov.io/gh/ivlevAstef/DITranquillity/branch/master/graph/badge.svg\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# DITranquillity\nTranquillity is a lightweight but powerful [dependency injection](https://en.wikipedia.org/wiki/Dependency_injection) library for swift.\n\nThe name \"Tranquillity\" laid the foundation in the basic principles of library: clarity, simplicity and security.\n\nIt says - use the library and you will be calm for your dependencies.\n\n\u003e Language switch: [English](README.md), [Russian](README_ru.md)\n\n## About Dependendy Injection\nDependency Injections is a software design pattern in which someone delivers dependencies to an object.\n\nIs one form of the broader technique of [Inversion Of Control](https://en.wikipedia.org/wiki/Inversion_of_control) and help the [Dependency Inversion Principle](https://en.wikipedia.org/wiki/Dependency_inversion_principle)\n\n[For more details you can read this link](Documentation/en/about_dependency_injection.md)\n\nAlso I recommend you to read [Glossary](Documentation/en/glossary.md) which will help to better understand the terms. \n\n## Features\n#### Core\n- [x] [Registration components and services](Documentation/en/core/registration_and_service.md)\n- [x] [Initializer/Property/Method Injections](Documentation/en/core/injection.md)\n- [x] [Optional and argument, many, by tag Injections](Documentation/en/core/modificated_injection.md)\n- [x] [Delayed injection](Documentation/en/core/delayed_injection.md)\n- [x] [Circular dependency injection](Documentation/en/core/injection.md)\n- [x] [Scope and lifetime](Documentation/en/core/scope_and_lifetime.md)\n- [x] [Modular](Documentation/en/core/modular.md)\n- [x] [Details logs](Documentation/en/core/logs.md)\n- [x] Thread safety\n- [x] Swift Concurrency\n- [x] [Container hierarchy](Documentation/en/core/container_hierarchy.md)\n#### UI\n- [x] [Storyboard and StoryboardReferences](Documentation/en/ui/storyboard.md)\n- [x] [Simple subviews and Cells Injection](Documentation/en/ui/view_injection.md)\n#### Graph API\n- [x] [Get dependency graph](Documentation/en/graph/get_graph.md)\n- [x] [Graph Validation](Documentation/en/graph/graph_validation.md)\n- [ ] [Visualization dependency graph](Documentation/en/graph/visualization_graph.md)\n\n## Installing\nThe library supports three popular package managers: Cocoapods, Carthage, SwiftPM.\n\nCocoapods unsupport from 5.0.0 library version.\n\n#### SwiftPM\nYou can use \"Xcode/File/Swift Packages/Add Package Dependency...\" and write github url:\n```\nhttps://github.com/ivlevAstef/DITranquillity\n```\n\nAlso you can edit your `Package.swift` and the following line into section `dependencies`:\n```Swift\n.package(url: \"https://github.com/ivlevAstef/DITranquillity.git\", from: \"5.0.0\")\n```\nAnd don't forget to specify in your section `target` wrote dependency line:\n```Swift\n.product(name: \"DITranquillity\")\n```\n\n#### CocoaPods\nAdd the following lines to your `Podfile`: \n```\npod 'DITranquillity'\n``` \n\n#### Carthage\nAdd the following lines to your `Cartfile`:\n```\ngithub \"ivlevAstef/DITranquillity\"\n```\n\n## Usage\nThe library uses a declarative style of dependency description, and allows you to separate your application code from dependency description code.\n\nFor a quick entry, let's look at an example code of one simplified VIPER screen:\n```Swift\n.................................................\n/// Dependency description\n\nlet container = DIContainer()\n\ncontainer.register(LoginRouter.init)\n\ncontainer.register(LoginPresenterImpl.init)\n  .as(LoginPresenter.self)\n  .lifetime(.objectGraph)\n\ncontainer.register(LoginViewController.init)\n  .injection(cycle: true, \\.presenter)\n  .as(LoginView.self)\n  .lifetime(.objectGraph)\n\ncontainer.register(AuthInteractorImpl.init)\n  .as(AuthInteractor.self)\n\n.................................................\n/// Application start point\n\nlet router: LoginRouter = container.resolve()\nwindow.rootViewController = router.rootViewController\nrouter.start()\n\n.................................................\n/// Application Code\n\nimport SwiftLazy\n\nclass LoginRouter {\n    let rootViewController = UINavigationController()\n    private let loginPresenterProvider: Provider\u003cLoginPresenter\u003e\n    \n    init(loginPresenterProvider: Provider\u003cLoginPresenter\u003e) {\n        loginPresenterProvider = loginPresenterProvider\n    }\n    \n    func start() {\n        let presenter = loginPresenterProvider.value\n        presenter.loginSuccessCallback = { [weak self] _ in\n            ...\n        }\n        // Your can write code without force cast, it's code simple example\n        rootViewController.push(presenter.view as! UIViewController)\n    }\n}\n\nprotocol LoginPresenter: class {\n    var loginSuccessCallback: ((_ userId: String) -\u003e Void)?\n    func login(name: String, password: String)\n}\n\nprotocol LoginView: class {\n    func showError(text: String)\n}\n\nclass LoginPresenterImpl: LoginPresenter {\n    private weak var view: LoginView?\n    private let authInteractor: AuthInteractor\n    init(view: LoginView, authInteractor: AuthInteractor) {\n        self.view = view\n        self.authInteractor = authInteractor\n    }\n    \n    func login(name: String, password: String) {\n        if name.isEmpty || password.isEmpty {\n            view?.showError(text: \"fill input\")\n            return\n        }\n        \n        authInteractor.login(name: name, password: password, completion: { [weak self] result in\n            switch result {\n            case .failure(let error): \n                self?.view?.showError(text: \"\\(error)\")\n            case .success(let userId):\n                self?.loginSuccessCallback?(userId)\n            }\n        })\n    }\n}\n\nclass LoginViewController: UIViewController, LoginView {\n    var presenter: LoginPresenter!\n    ...\n    func showError(text: String) {\n        showAlert(title: \"Error\", message: text)\n    }\n    \n    private func tapOnLoginButton() {\n        presenter.login(name: nameTextField.text ?? \"\", password: passwordTextField.text ?? \"\")\n    }\n}\n\nprotocol AuthInteractor: class {\n    func login(name: String, password: String, completion: (Result\u003cString, Error\u003e) -\u003e Void)\n}\n\nclass AuthInteractorImpl: AuthInteractor {\n    func login(name: String, password: String, completion: (Result\u003cString, Error\u003e) -\u003e Void) {\n        ...\n    }\n}\n```\nAs you can see, the dependency description code takes a small part, and the application code doen't know about how dependencies are implemented.  \n\nAlso your can show samples:\n* [For habr](Samples/SampleHabr/)\n* [Chaos](Samples/SampleChaos/)\n* [Delegate and observer](Samples/SampleDelegateAndObserver/)\n* [SwiftPM big clean architecture](https://github.com/ivlevAstef/FunCorpSteamApp)\n\nAlso your can read articles:\n* Ru! [https://habr.com/ru/post/457188/](https://habr.com/ru/post/457188/) \n* Ru! Old! [https://habr.com/ru/post/311334/](https://habr.com/ru/post/311334/)\n\n## Requirements\niOS 13.0+,macOS 10.15+,tvOS 13.0+, watchOS 8.0+, Linux; ARC\n\n* Swift 6.0-6.x: Xcode 16; version \u003e= 5.0.0\n* Swift 5.5-5.9: Xcode 13,14,15; version \u003e= 3.6.3\n* Swift 5.0-5.3: Xcode 10.2-12.x; version \u003e= 3.6.3\n* Swift 4.2: Xcode 10; version \u003e= 3.4.3\n* Swift 4.1: Xcode 9.3; version \u003e= 3.2.3\n* Swift 4.0: Xcode 9.0; version \u003e= 3.0.5\n* Swift 3.0-3.2: Xcode 8.0-9.0; 0.9.5 \u003c= version \u003c 3.7.0\n* Swift 2.3: Xcode 7.0; version \u003c 0.9.5\n\n## Changelog\nSee [CHANGELOG](CHANGELOG.md) file or [releases](https://github.com/ivlevAstef/DITranquillity/releases).\n\n## Feedback\n\n### I've found a bug, or have a feature request\nPlease raise a [GitHub issue](https://github.com/ivlevAstef/DITranquillity/issues).\n\n### I've found a defect in documentation, or thought up how to improve it\nPlease help library development and create [pull requests](https://github.com/ivlevAstef/DITranquillity/pulls)\n\n### Plea\nIf you like my library, then support the library by putting star.\n\n### Question?\nYou can feel free to ask the question at e-mail: ivlev.stef@gmail.com.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FivlevAstef%2FDITranquillity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FivlevAstef%2FDITranquillity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FivlevAstef%2FDITranquillity/lists"}