Skip to content

ltp88/swift-injector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift Dependency Injector

How to use

For development module

class DevModule: AbstractModule {
  override func configure() {
    super.configure()

    bind(String.self).withName("api-host").to("http://api.development.com")

    bind(FooService.self).to(DevFooServiceImpl())
    bind(BarService.self).to(BarServiceImpl())
  }
}

For testing module

class TestModule: DevModule {
  override func configure() {
    super.configure()

    bind(String.self).withName("api-host").to("http://api.localhost.com")

    bind(BarService.self).to(FakedServiceImpl())
  }
}

For production module

class ProdModule: DevModule {
  override func configure() {
    super.configure()

    bind(String.self).withName("api-host").to("http://api.production.com")

    bind(FooService.self).to(ProdFooServiceImpl())
  }
}

In app delegate

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  Injectors.initialize(modules: DevModule())

  //...
  return true
}

get instance

  let fooService = Injectors.get(FooService.self)
  fooService.foo()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages