Code Monkey home page Code Monkey logo

cleansedi's Introduction

CleanseDI

More detail what is Cleanse

Terminology

Components and subcomponents

Your object will start with a RootComponent and Component represent an object graph that used to inject object.

Modules

Modules are the building blocks for components (one object graph). They are the way to define how the dependencies are going to be instantiated.

Scopes

Scopes are the way to define the lifecycle of dependencies. Cleanse provides two scopes:

  • Singleton Used to tell the binder that you want it to use the same instance when providing the dependency.

  • Unscoped Used to a new instance will be instantiated every time.

Binder

module configuration use to configure their providers. There are 2 core methods:

  • Simpler one (One passes it an instance of a module to be installed)
binder.include(module: PrimaryAPIURLModule.self)
  • Argument Binding(takes one argument)
bind<E>(type: E.Type)

bind() returns a BindingBuilder that one must call methods on to complete the configuration of the binding that was instantiated.

Type Tags

Tags are a way to provide named parameters to our objects. Use Tag to tag object type.

public struct PrimaryAPIURL : Tag {
   typealias Element = NSURL
}

TaggedProvider<PrimaryAPIURL>

Property Injection

The way have to provide dependencies to an object after its instantiation. This particularly useful when the system instantiates the object such as AppDelegate, Scene Delegate.

Assisted Injection

A technique where provide additional objects to object instantiation that are not part of the graph. Use this, when combining seeded parameters.

extension CustomerDetailViewController {
    // Factory
    struct Seed: AssistedFactory {
        typealias Seed = String
        typealias Element = CustomerDetailViewController
    }

    struct Module: Cleanse.Module {
        static func configure(binder: Binder<Unscoped>) {
            binder
              .bindFactory(CustomerDetailViewController.self)
              .with(AssistedFactory.self) // Assisted Injection
              .to(factory: CustomerDetailViewController.init)
        }
    }
}

Multibindings / Collection Bindings

Simple concept where the object you provides are put into an array or collection.

cleansedi's People

Contributors

wliamgho avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.