DependencyManager 1.0.0

DependencyManager 1.0.0

Maintained by Michael Vorontsov.



  • By
  • Michael Vorontsov

DependencyManager

CI Status Version License Platform

DependencyManager provides simple interface for declaring weak dependencies. Weak means that dependencies will live in memory as long as some other part of app keep using it, and will autoreleased when it's no longer needed, reducing memory footprint.

DepedencyManager itself provides ability to retrieve/create new services by keys using swift resolve<T>(key: String, creator: () -> (T)) function by unique key for services and creator block that should be called when services had to be recreated.

Generally it is recommended to describe public interface to intended services as Protocol then, then provide implementation as private class conforming to the protocol and in that same file declare extension to DependencyManagerProtocol to create specific implementation as the protocol:

protocol FetchStringsServiceProtocol: PublicServicePorotocol {
   func fetchStrings(handler:  (([String]) -> () ) )
}

extension DependencyManagerProtocol {
   func resolveFetchStringsService() -> FetchServiceProtocol {
       return self.resolve(key: "StringService") {
           StringServiceImp(...)
       }
   }
}
 
private class StringServiceImp: FetchStringsServiceProtocol {
   
   func fetchStrings(handler:  (([String]) -> () ) ) {
       ...
   }
}

Please see Expample for additional details.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Framework compliant with Swift4.2 and by so require XCode10.

Installation

DependencyManager is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'DependencyManager'

Or via Carthage

github "Michael-Vorontsov/DependencyManager"

Author

Michael Vorontsov, [email protected]

License

DependencyManager is available under the MIT license. See the LICENSE file for more info.