Skip to content

Whatever you Need, wherever you Need it, you can get it! Swift based dependency injection implementation.

License

Notifications You must be signed in to change notification settings

leloupnicolas/Need

Repository files navigation

License Platform CocoaPod

A Swift based Dependency Injection implementation. Wherever you Need a service, you can get it.

Features

  • Service Locator
  • Services injection aware utility class.

Installation

The only way is to use CocoaPods.

CocoaPods

To install Need, include the following in your Podfile

  pod 'Need', '~> 1.0'

How To

Setup

After adding the framework to your project, you need to import the module in your AppDelegate

import Need

Now, a LazyServiceLocator attribute to your AppDelegate :

  /// The main service locator
  let lazyServiceLocator: LazyServiceLocator = LazyServiceLocator()

Add the following before the return statement of the application(_ application:didFinishLaunchingWithOptions:) method:

  self.processRegistration()

To finish, implement the `ServicesRegistry' protocol as the following:

extension AppDelegate: ServicesRegistry {
  var serviceLocator: ServiceLocator {
    return self.lazyServiceLocator
  }

  func processRegistration() {
    // Add here your own services
    // self.lazyServiceLocator.addService(OwnServiceImplementation() as OwnServiceProtocol)
  }
}

Usage

Utility classes ServicesInjectionAware and ServicesInjectionAwareViewController are available in Need. You can use it as the following:

class OwnViewController: ServicesInjectionAwareViewController {
  lazy var ownService: OwnServiceProtocol = {
    return getService()
  }()
  
  // Use your own service wherever you need.
}

Contributing

  • If you need help, have a feature request or found a bug, open an issue.
  • If you want to contribute, submit a pull request.

Credits

Need is owned and maintained by Nicolas LELOUP @leloupnicolas.

License

This project is licensed under the MIT license.

Copyright (c) 2017 Nicolas LELOUP

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Whatever you Need, wherever you Need it, you can get it! Swift based dependency injection implementation.

Resources

License

Stars

Watchers

Forks

Packages

No packages published