All Projects → ivlevAstef → Ditranquillity

ivlevAstef / Ditranquillity

Licence: mit
Dependency injection for iOS (Swift)

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Ditranquillity

waiter
Dependency injection, Inversion of control container for rust with compile time binding.
Stars: ✭ 71 (-77.6%)
Mutual labels:  ioc, dependency-injection, inversion-of-control, di
diod
A very opinionated inversion of control (IoC) container and dependency injector for Typescript, Node.js or browser apps.
Stars: ✭ 36 (-88.64%)
Mutual labels:  ioc, dependency-injection, inversion-of-control, di
vesselize
⛵ A JavaScript IoC container that works seamlessly with Vue.js and React.
Stars: ✭ 22 (-93.06%)
Mutual labels:  ioc, dependency-injection, inversion-of-control, di
Typhoon
Powerful dependency injection for Objective-C ✨✨ (https://PILGRIM.PH is the pure Swift successor to Typhoon!!)✨✨
Stars: ✭ 2,711 (+755.21%)
Mutual labels:  dependency-injection, ioc, inversion-of-control, di
stashbox
A lightweight, fast, and portable dependency injection framework for .NET-based solutions.
Stars: ✭ 120 (-62.15%)
Mutual labels:  ioc, dependency-injection, inversion-of-control, di
Singularity
A extremely fast ioc container for high performance applications
Stars: ✭ 63 (-80.13%)
Mutual labels:  dependency-injection, ioc, inversion-of-control, di
Container Ioc
Inversion of Control container & Dependency Injection for Javascript and Node.js apps powered by Typescript.
Stars: ✭ 89 (-71.92%)
Mutual labels:  dependency-injection, ioc, inversion-of-control, di
DI-compiler
A Custom Transformer for Typescript that enables compile-time Dependency Injection
Stars: ✭ 62 (-80.44%)
Mutual labels:  ioc, dependency-injection, di
Ioc
🦄 lightweight (<1kb) inversion of control javascript library for dependency injection written in typescript
Stars: ✭ 171 (-46.06%)
Mutual labels:  dependency-injection, ioc, inversion-of-control
Kangaru
🦘 A dependency injection container for C++11, C++14 and later
Stars: ✭ 297 (-6.31%)
Mutual labels:  dependency-injection, ioc, inversion-of-control
Qframework
Unity3D System Design Architecture
Stars: ✭ 2,326 (+633.75%)
Mutual labels:  dependency-injection, ioc, inversion-of-control
iocgo
A lightweight Inversion of Control (IoC) (Dependency Injection) container for Golang
Stars: ✭ 36 (-88.64%)
Mutual labels:  ioc, dependency-injection, inversion-of-control
awilix-express
Awilix helpers/middleware for Express
Stars: ✭ 100 (-68.45%)
Mutual labels:  dependency-injection, inversion-of-control, di
Typedi
Simple yet powerful dependency injection tool for JavaScript and TypeScript.
Stars: ✭ 2,832 (+793.38%)
Mutual labels:  dependency-injection, ioc, inversion-of-control
di
🛠 A full-featured dependency injection container for go programming language.
Stars: ✭ 156 (-50.79%)
Mutual labels:  ioc, dependency-injection, di
inject
[Archived] See https://github.com/goava/di.
Stars: ✭ 49 (-84.54%)
Mutual labels:  ioc, dependency-injection, di
CNeptune
CNeptune improve productivity & efficiency by urbanize .net module with meta-code to lay foundation for frameworks
Stars: ✭ 30 (-90.54%)
Mutual labels:  ioc, inversion-of-control, di
ThunderboltIoc
One of the very first IoC frameworks for .Net that has no reflection. An IoC that casts its services before thunder casts its bolts.
Stars: ✭ 40 (-87.38%)
Mutual labels:  ioc, dependency-injection, inversion-of-control
React Ioc
Hierarchical Dependency Injection with new React 16 Context API
Stars: ✭ 133 (-58.04%)
Mutual labels:  dependency-injection, ioc, inversion-of-control
Hiboot
hiboot is a high performance web and cli application framework with dependency injection support
Stars: ✭ 150 (-52.68%)
Mutual labels:  dependency-injection, ioc, di

Tranquillity

DITranquillity

Tranquillity is a lightweight but powerful dependency injection library for swift.

The name "Tranquillity" laid the foundation in the basic principles of library: clarity, simplicity and security.

It says - use the library and you will be calm for your dependencies.

Language switch: English, Russian

About Dependendy Injection

Dependency Injections is a software design pattern in which someone delivers dependencies to an object.

Is one form of the broader technique of Inversion Of Control and help the Dependency Inversion Principle

For more details you can read this link

Also I recommend you to read Glossary which will help to better understand the terms.

Features

Core

UI

Graph API

Installing

The library supports three popular package managers: Cocoapods, Carthage, SwiftPM.

CocoaPods

Add the following lines to your Podfile:

pod 'DITranquillity'

SwiftPM

You can use "Xcode/File/Swift Packages/Add Package Dependency..." and write github url:

https://github.com/ivlevAstef/DITranquillity

Also you can edit your Package.swift and the following line into section dependencies:

.package(url: "https://github.com/ivlevAstef/DITranquillity.git", from: "3.8.4")

And don't forget to specify in your section target wrote dependency line:

.product(name: "DITranquillity")

Attention! - SwiftPM unsupport features from the "UI" section.

Carthage

Add the following lines to your Cartfile:

github "ivlevAstef/DITranquillity"

Carthage support "UI" and "GraphAPI" section no additional actions.

Usage

The library uses a declarative style of dependency description, and allows you to separate your application code from dependency description code.

For a quick entry, let's look at an example code of one simplified VIPER screen:

.................................................
/// Dependency description

let container = DIContainer()

container.register(LoginRouter.init)

container.register(LoginPresenterImpl.init)
  .as(LoginPresenter.self)
  .lifetime(.objectGraph)

container.register(LoginViewController.init)
  .injection(cycle: true, \.presenter)
  .as(LoginView.self)
  .lifetime(.objectGraph)

container.register(AuthInteractorImpl.init)
  .as(AuthInteractor.self)

.................................................
/// Application start point

let router: LoginRouter = container.resolve()
window.rootViewController = router.rootViewController
router.start()

.................................................
/// Application Code

import SwiftLazy

class LoginRouter {
    let rootViewController = UINavigationController()
    private let loginPresenterProvider: Provider<LoginPresenter>
    
    init(loginPresenterProvider: Provider<LoginPresenter>) {
        loginPresenterProvider = loginPresenterProvider
    }
    
    func start() {
        let presenter = loginPresenterProvider.value
        presenter.loginSuccessCallback = { [weak self] _ in
            ...
        }
        // Your can write code without force cast, it's code simple example
        rootViewController.push(presenter.view as! UIViewController)
    }
}

protocol LoginPresenter: class {
    var loginSuccessCallback: ((_ userId: String) -> Void)?
    func login(name: String, password: String)
}

protocol LoginView: class {
    func showError(text: String)
}

class LoginPresenterImpl: LoginPresenter {
    private weak var view: LoginView?
    private let authInteractor: AuthInteractor
    init(view: LoginView, authInteractor: AuthInteractor) {
        self.view = view
        self.authInteractor = authInteractor
    }
    
    func login(name: String, password: String) {
        if name.isEmpty || password.isEmpty {
            view?.showError(text: "fill input")
            return
        }
        
        authInteractor.login(name: name, password: password, completion: { [weak self] result in
            switch result {
            case .failure(let error): 
                self?.view?.showError(text: "\(error)")
            case .success(let userId):
                self?.loginSuccessCallback?(userId)
            }
        })
    }
}

class LoginViewController: UIViewController, LoginView {
    var presenter: LoginPresenter!
    ...
    func showError(text: String) {
        showAlert(title: "Error", message: text)
    }
    
    private func tapOnLoginButton() {
        presenter.login(name: nameTextField.text ?? "", password: passwordTextField.text ?? "")
    }
}

protocol AuthInteractor: class {
    func login(name: String, password: String, completion: (Result<String, Error>) -> Void)
}

class AuthInteractorImpl: AuthInteractor {
    func login(name: String, password: String, completion: (Result<String, Error>) -> Void) {
        ...
    }
}

As you can see, the dependency description code takes a small part, and the application code doen't know about how dependencies are implemented.

Also your can show samples:

Also your can read articles:

Requirements

iOS 9.0+,macOS 10.10+,tvOS 9.0+, watchOS, linux; ARC

  • Swift 5.0-5.3: Xcode 10.2-12.3; version >= 3.6.3
  • Swift 4.2: Xcode 10; version >= 3.4.3
  • Swift 4.1: Xcode 9.3; version >= 3.2.3
  • Swift 4.0: Xcode 9.0; version >= 3.0.5
  • Swift 3.0-3.2: Xcode 8.0-9.0; 0.9.5 <= version < 3.7.0
  • Swift 2.3: Xcode 7.0; version < 0.9.5

Changelog

See CHANGELOG file or releases.

History and Plans

  • [x] v1.x.x - Started
  • [x] v2.x.x - Stabilization
  • [x] v3.x.x - Evolution and Features
  • [ ] v4.x.x - Graph API and Optimization. Also Documentation and Marketing
  • [ ] v5.x.x - Pre compile time validation

Feedback

I've found a bug, or have a feature request

Please raise a GitHub issue.

I've found a defect in documentation, or thought up how to improve it

Please help library development and create pull requests

Plea

If you like my library, then support the library by putting star.

You can also support the author of the library with a donation:

Donate

Question?

You can feel free to ask the question at e-mail: [email protected].

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].