Skip to content

avreolko/VCDependency

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tests

VCDependency

Basic dependency lifecycle management.

Features

  • Factory
  • Single
  • Weak single

Usage example

final class Container {

    // The lifecycle of this repository is the same as the lifecycle of the container itself
    lazy var sharedRepository = Single { Repository() }

    // Сontainer weakly references this repo.
    // If the repos was freed from memory, then it will be rebuilt on the next `get()` call.
    lazy var repository = WeakSingle { Repository() }
    
    // Object will be rebuilt on each `get()` call.
    lazy var uniqueRepository = Factory { Repository() }
    
    // Example where objects refer to each other.
    lazy var otherRepository = Single { [sharedRepository] in 
        OtherObject(repository: sharedRepository.get())
    }
}

License

This project is released under the MIT license.

About

Painless dependency lifecycle management

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages