ProjectI is a lightweight, robust dependency injection (DI) framework built for Swift. It aims to simplify dependency management in Swift applications, offering a clean and easy-to-use API for integrating service dependencies.
- Efficient Dependency Injection: Utilize a singleton DI container to manage your application's services.
- Type-Safe: Ensures that dependencies are resolved in a type-safe manner.
- Simple API: Easy to use API with
@Injectproperty wrappers for automatic dependency resolution.
You can add ProjectI to your project using Swift Package Manager (SPM).
Add ProjectI as a dependency to your Package.swift:
letpackage=Package(
name:"YourPackageName",
dependencies:[.package(url:"https://github.com/jsambuo/ProjectI.git",.upToNextMajor(from:"1.0.0"))],
targets:[.target(
name:"YourTargetName",
dependencies:["ProjectI"])])First, import ProjectI in the file you want to use it:
import ProjectIBefore you can use @Inject, you need to register your services with the container:
DIContainer.shared.register(ExampleServiceInterface.self, service:ExampleService())Simply use the @Inject property wrapper to automatically inject dependencies:
classMyClass{@Injectvarservice:ExampleServiceInterfacefunc performAction(){
service.doSomething()}}ProjectI provides error handling to manage duplicate registrations:
do{tryDIContainer.shared.register(ExampleServiceInterface.self, service:ExampleService())}catchDIContainerError.serviceAlreadyRegistered {print("This service is already registered.")}Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
To contribute to ProjectI, follow these steps:
- Fork the project.
- Create your feature branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a pull request.
Distributed under the MIT License. See LICENSE for more information.
Your Name – @jsambuo - jsambuo@gmail.com
Project Link: https://github.com/jsambuo/ProjectI