Latest 1.1.0
Homepage https://github.com/leloupnicolas/Need
License MIT
Platforms ios 8.0
Authors

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.

Latest podspec

{
    "name": "Need",
    "version": "1.1.0",
    "summary": "Need is a swift-based dependency injection utility.",
    "description": "Need is a swift-based dependency injection utility for iOS apps. Whatever you need as a service, wherever you need it.",
    "homepage": "https://github.com/leloupnicolas/Need",
    "license": "MIT",
    "authors": {
        "leloupnicolas": "[email protected]"
    },
    "source": {
        "git": "https://github.com/leloupnicolas/Need.git",
        "tag": "1.1.0"
    },
    "social_media_url": "https://twitter.com/leloupnicolas",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Need",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This