Skip to content

a easy to understand dependency injection container for swift

License

Notifications You must be signed in to change notification settings

OlafConijn/SimpleDI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleDi easy to understand DI and IoC for swift

SimpleDI : an easy to understand dependency injection (di) and inversion of control (ioc) container for swift.

creating a container:

    let c = Container()

registering/resolving simple types:

    c.registerInstance(42)  //registers an Int
    c.register({ 42 }) //registers an Int 'lazyly'
    42 == c.resolve() //returns true

registering/resolving a service using protocol:

    c.register({ MyClass() as MyProtocol }) //registers concrete class as protocol
    c.resolve()! as MyProtocol //resolves instance of MyClass
    c.resolve()! is MyClass //evaluates to true

dependency injection:

    contaienr.register({ c in MyClass(c.resolve(), arg2: c.resolve(), arg3: c.resolve()) }) //dependency injection
    let cl = contaienr.resolve()! as MyClass //resolves the whole dependency tree

registering a non-singleton class:

    c.register({ MyClass() }, singleton: false) //registers as transient class
    let p = c.resolve()! as MyClass
    let p2 = c.resolve()! as MyClass
    p !== p2 //returns true

About

a easy to understand dependency injection container for swift

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages