{"id":13338684,"url":"https://github.com/munirwanis/Vaccine","last_synced_at":"2025-03-11T10:31:44.272Z","repository":{"id":95251964,"uuid":"296931679","full_name":"munirwanis/Vaccine","owner":"munirwanis","description":"Simple dependency injection library using Swift property wrappers.","archived":false,"fork":false,"pushed_at":"2021-06-14T21:55:40.000Z","size":394,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-26T21:36:33.324Z","etag":null,"topics":["dependency-injection","hacktoberfest","ios","ipados","macos","property-wrappers","swift","swift-property-wrappers","tvos","watchos"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/munirwanis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-19T18:49:38.000Z","updated_at":"2021-08-23T17:57:26.000Z","dependencies_parsed_at":"2023-04-04T13:00:37.415Z","dependency_job_id":null,"html_url":"https://github.com/munirwanis/Vaccine","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munirwanis%2FVaccine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munirwanis%2FVaccine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munirwanis%2FVaccine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munirwanis%2FVaccine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/munirwanis","download_url":"https://codeload.github.com/munirwanis/Vaccine/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243015428,"owners_count":20222080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dependency-injection","hacktoberfest","ios","ipados","macos","property-wrappers","swift","swift-property-wrappers","tvos","watchos"],"created_at":"2024-07-29T19:17:08.468Z","updated_at":"2025-03-11T10:31:44.258Z","avatar_url":"https://github.com/munirwanis.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vaccine\n\n![Version](https://img.shields.io/github/v/release/munirwanis/Vaccine?style=flat)\n[![Swift Package Manager](https://img.shields.io/badge/swift%20package%20manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)\n![Platforms](https://img.shields.io/static/v1?label=Platforms\u0026message=iOS%20|%20macOS%20|%20tvOS%20|%20watchOS%20|%20Linux\u0026color=brightgreen\u0026style=flat)\n![Build](https://img.shields.io/github/workflow/status/munirwanis/Vaccine/Swift?style=flat)\n![License](https://img.shields.io/github/license/munirwanis/Vaccine?style=flat)\n[![Tweet](https://img.shields.io/twitter/url?style=social\u0026url=https%3A%2F%2Fgithub.com%2Fmunirwanis%2FVaccine)](https://twitter.com/intent/tweet?text=Wow:\u0026url=https%3A%2F%2Fgithub.com%2Fmunirwanis%2FVaccine)\n\n## Simple dependency injection library using Swift property wrappers\n\nTired of creating a lot of property on initializers of your classes so it's easier to test them? With **Vaccine** is possible to define properties in your classes using `@propertyWrapper`s in a very simple way!\n\n## Installation\n\n### Swift Package Manager\n\nIn **Xcode** go to `File-\u003eSwift Packages-\u003eAdd Package Dependency...` and paste the url:\n\n`https://github.com/munirwanis/Vaccine.git`\n\nIf you are adding this package as a dependency to another package, paste this on your `Package.swift` file:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/munirwanis/Vaccine.git\", .upToNextMajor(from: \"1.0.0\" )),\n]\n```\n\n### Manual\n\nSince this project has no dependencies, it's possible to drag the source files to your project.\n\n### Other package managers\n\nIf manual or SPM are not a option, pull requests will be very welcome to help support other platforms.\n\n## Compatibility\n\n- [X] **Swift 5.1+**\n- [X] **Xcode 11+**\n\n## Usage\n\n### Register dependencies\n\nYou can use the starting point of your application to register the dependencies that will be resolved later. Let's say we have a protocol for a service called `SomeServiceProtol`, and I want to resolve it with my class `SomeService`.\n\n```swift\nimport Foundation\nimport Vaccine\n\n@UIApplicationMain\nclass AppDelegate: UIResponder, UIApplicationDelegate {\n    \n    \n    func application(_ application: UIApplication,\n                     configurationForConnecting connectingSceneSession: UISceneSession,\n                     options: UIScene.ConnectionOptions) -\u003e UISceneConfiguration {\n        \n        // Registers the dependency for my service\n        Vaccine.setCure(for: SomeServiceProtocol.self, with: SomeService())\n\n        return UISceneConfiguration(name: \"Default Configuration\", sessionRole: connectingSceneSession.role)\n    }\n}\n```\n\nYou can also set the property `isUnique` to `true` to ensure that the object injected is singleton.\n\n```swift\nVaccine.setCure(for: SomeServiceProtocol.self, isUnique: true, with: SomeService())\n```\n\nIf your object needs to do some complex things you can also pass the resolver as a closure, like this:\n\n```swift\n// Can also use `isUnique` property\nVaccine.setCure(for: SomeServiceProtocol.self) {\n    let item = [\"Hello\", \"World\"].randomElement() ?? \"\"\n    return SomeService(text: item)\n}\n```\n\n### Resolve dependencies\n\nTo resolve dependencies is pretty simple, simply use `@Inject` property wrapper inside your class:\n\n```swift\nclass SomeViewModel {\n    // Will instantiate or get an already instantiated (if singleton) version of  `SomeService`\n    @Inject(SomeServiceProtocol.self) var service\n    \n    func getText() -\u003e String {\n        service.getText()\n    }\n}\n```\n\n### Contributions\n\nFound a bug or have a improvement suggestion? Open a issue or help by submitting a Pull Request! 😊\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmunirwanis%2FVaccine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmunirwanis%2FVaccine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmunirwanis%2FVaccine/lists"}