Dependency Injector is a powerful and flexible dependency injection container for Objective-C and Swift. It allows you to simplify and manage dependencies in your code, making it easier to maintain and test.
Features
- Supports both Objective-C and Swift projects.
- Provides a simple and intuitive API for dependency injection.
- Allows dependency injection through property injection, initializer injection, and method injection.
- Enables the configuration of object scopes, including singleton and transient.
- Supports automatic resolution of circular dependencies.
- Provides advanced features like object lifecycle management and auto-wiring of dependencies.
- Offers built-in support for constructor-based and property-based dependency injection.
Installation
CocoaPods
To install Dependency Injector using CocoaPods, add the following line to your Podfile:
pod 'DependencyInjector', '~> 1.0'
Then, run the following command:
$ pod install
Carthage
To install Dependency Injector using Carthage, add the following line to your Cartfile:
github "DependencyInjector/DependencyInjector" ~> 1.0
Then, run the following command:
$ carthage update
Getting Started
Objective-C
To start using Dependency Injector in your Objective-C project, follow these steps:
- Create a new instance of the Injector:
- Register your dependencies:
- Resolve a dependency:
#import "DIInjector.h"
DIInjector *injector = [[DIInjector alloc] init];
#import "DIService.h"
[injector register:[DIService class]];
id<DIService> service = [injector resolve:@protocol(DIService)];
Swift
To start using Dependency Injector in your Swift project, follow these steps:
- Create a new instance of the Injector:
- Register your dependencies:
- Resolve a dependency:
import DependencyInjector
let injector = DIInjector()
import DependencyInjector
injector.register(DIService.self)
import DependencyInjector
let service: DIService = injector.resolve(DIService.self)
Documentation
For detailed documentation and usage examples, please refer to the official Dependency Injector repository.
Contributions
If you find any issues or have suggestions for improvements, feel free to contribute to the project by submitting a pull request on the official GitHub repository.
License
Dependency Injector is available under the permissive MIT license. See the LICENSE file for more information.