Skip to content

Latest commit

 

History

History
49 lines (38 loc) · 1.41 KB

README.md

File metadata and controls

49 lines (38 loc) · 1.41 KB

💉 Refds Injection

Swift

RefdsInjection is a Swift library that provides a simple yet powerful solution for dependency injection in your iOS, macOS, and other Swift applications. With RefdsInjection, you can manage your components' dependencies cleanly and efficiently, easing the development, testing, and maintenance of your codebase.

Installation

Add this project to your Package.swift file.

import PackageDescription

let package = Package(
    dependencies: [
        .package(url: "https://github.com/rafaelesantos/refds-injection.git", branch: "main")
    ],
    targets: [
        .target(
            name: "YourProject",
            dependencies: [
                .product(
                    name: "RefdsInjection",
                    package: "refds-injection"),
            ]),
    ]
)

Usage

import RefdsInjection

protocol MockViewModelProtocol {
    var id: UUID { get }
}

class MockViewModel: MockViewModelProtocol {
    var id: UUID
    init(id: UUID) { self.id = id }
}

let expectedID = UUID()
RefdsContainer.register(type: MockViewModelProtocol.self) { MockViewModel(id: expectedID) }
let viewModel = RefdsContainer.resolve(type: MockViewModelProtocol.self)
let receivedID = viewModel.id