document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import Swinject
  2.  
  3. extension SwinjectStoryboard {
  4.     class func setup() {
  5.        
  6.     // Registering concrete classes
  7.     // You can use protocols instead and you\'ll be able to use Swinject in your Unit Tests too!
  8.     // It\'s important to call .inObjectScope(.Container), so Swinject uses the same object instance
  9.     // for all resolves
  10.         defaultContainer.register(DatabaseContext.self) { _ in DatabaseContext() }.inObjectScope(.Container)
  11.         defaultContainer.register(NetworkingContext.self) { _ in NetworkingContext() }.inObjectScope(.Container)
  12.         defaultContainer.register(LocalConfigContext.self) { _ in LocalConfigContext() }.inObjectScope(.Container)
  13.         defaultContainer.register(ViewModelContext.self){ _ in ViewModelContext() }.inObjectScope(.Container)
  14.        
  15.     // Registering View Controller in the storyboard
  16.         defaultContainer.registerForStoryboard(ViewController.self) { r, c in
  17.             c.database = r.resolve(DatabaseContext.self)
  18.             c.networking = r.resolve(NetworkingContext.self)
  19.             c.config = r.resolve(LocalConfigContext.self)
  20.             c.viewModel = r.resolve(ViewModelContext.self)
  21.         }
  22.    
  23.     // Registering the second view controller
  24.         defaultContainer.registerForStoryboard(SecondViewController.self) { r, c in
  25.             c.database = r.resolve(DatabaseContext.self)
  26.             c.networking = r.resolve(NetworkingContext.self)
  27.             c.viewModel = r.resolve(ViewModelContext.self)
  28.         }
  29.  
  30.     }
  31.    
  32. }
');