Skip to content

iamchiwon/DependencyInjection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Dependency Injection Example

Usage

Step 1 : Regist instance with protocol

Configurator.shared.regist(type: SampleInteractorPtorocol.self, instance: SampleInteractor())

Step2 : Define protocol, Inject the instance and use it

protocol SampleInteractorPtorocol {
  func doSomething()
}

class ViewController: UIViewController {
  
  lazy var interactor = Configurator.shared.inject(type: SampleInteractorPtorocol.self)

  override func viewDidLoad() {
    super.viewDidLoad()
    
    interactor?.doSomething()
  }
}

Step3 : Implements the protocol

class SampleInteractor : SampleInteractorPtorocol {
  func doSomething() {
    print("doing something")
  }
}

DI Configurator

Reference

Useful for clean-swift architecture, a.k.a VIP

Other Swift DI Libs

About

iOS 에서 DI 예제

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages