{"id":27938549,"url":"https://github.com/willowtreeapps/grove","last_synced_at":"2025-05-07T08:49:12.953Z","repository":{"id":230279616,"uuid":"747968171","full_name":"willowtreeapps/grove","owner":"willowtreeapps","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-21T13:57:55.000Z","size":28,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-08-21T15:29:34.665Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willowtreeapps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-01-25T01:54:22.000Z","updated_at":"2024-08-21T13:57:59.000Z","dependencies_parsed_at":"2024-05-01T20:57:56.995Z","dependency_job_id":null,"html_url":"https://github.com/willowtreeapps/grove","commit_stats":null,"previous_names":["willowtreeapps/grove"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willowtreeapps%2Fgrove","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willowtreeapps%2Fgrove/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willowtreeapps%2Fgrove/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willowtreeapps%2Fgrove/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willowtreeapps","download_url":"https://codeload.github.com/willowtreeapps/grove/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252847249,"owners_count":21813438,"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":[],"created_at":"2025-05-07T08:49:12.487Z","updated_at":"2025-05-07T08:49:12.939Z","avatar_url":"https://github.com/willowtreeapps.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Grove\nSimple Swift Dependency Injection Container.\nSomewhat like a grove is a group of trees, Grove's container represents a group of dependencies, and it provides you with tools to easily manage them.\n\n## Description\nGrove is a super simple and lightweight Dependency Injection library available for Swift. It's designed to help you manage a group of dependencies in a container, and easily resolve them when needed, thus helping make your project more modular, testable, and maintainable.\n\n## Features\n- **Lightweight and Focused** - Specifically responsible for dealing with dependency injection.\n- **Swift-native Design** - Grove feels natural and intuitive for Swift developers.\n- **Scoped Instances** - Capable of setting dependencies' lifetime scope (as singleton or transient).\n- **Thread-safe** - Grove maintains thread-safety when registering and resolving dependencies.\n- **Simple** - With Grove's `@Resolve` property wrapper, usage is cleaner and super easy.\n\n## Installation\nGrove is available through the Swift Package Manager. To install it, simply add the following line to your `Package.swift` file:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/willowtreeapps/grove.git\", from: \"1.1.2\")\n]\n```\n\n## Usage\nGrove simplifies dependency registration and resolving. Here's an example:\n\n### Registration\n\n```swift\nlet container = Grove.defaultContainer // You can use the default container or create your own\n\n// Register specifying a type to use for resolution\ncontainer.register(as: NASARepositoryProtocol.self, NASARepository())\n\n// Register a reference type dependency as a singleton \ncontainer.register(JSONEncoder())\n\n// or with a transient lifetime\ncontainer.register(scope: .transient, JSONEncoder())\n\n// Register a value type dependency (an enum for example)\ncontainer.register(DeploymentEnvironment.production)\n```\n\n### Resolution\n\n```swift\n// Later in your code, you can resolve the dependency\nlet jsonEncoder: JSONEncoder = container.resolve()\n\n// Alternatively, you can use the @Resolve property wrapper:\n@Resolve(JSONEncoder.self) var jsonEncoder\n\n// Value types are resolved the same way (here deploymentEnvironment would be .production)\n@Resolve(DeploymentEnvironment.self) var deploymentEnvironment\n```\n\n### Using the included registrar\n\nThis shows how you can set up a registrar class both for production and for unit tests and SwiftUI previews:\n\n```swift\nimport Grove\n\n@main\nstruct YourApp: App {\n\n    init() {\n        GroveRegistrar.register(\n            /// Registers dependencies that will be used normally by the app\n            baseDependencies: { container in\n                container.register(as: Environment.self, Environment.production)\n                container.register(as: NASARepositoryProtocol.self, NASARepository())\n            },\n            /// Registers overrides to be used by the app during development (RUNNING_IN_DEVELOPMENT_MODE environment variable)\n            developmentOverrides: { container in\n                container.register(as: Environment.self, Environment.local)\n                container.register(as: NASARepositoryProtocol.self, MockNASARepository())\n            },\n            /// Registers overrides to be used by the app during unit tests and swiftui previews \n            unitTestOverrides: { container in\n                container.register(as: Environment.self, Environment.local)\n                container.register(as: NASARepositoryProtocol.self, MockNASARepository())\n            },\n            /// Registers dependencies to be used by the app during UI automation tests\n            uiAutomationOverrides: { container in\n                container.register(as: Environment.self, Environment.mockService)\n            }\n        )\n    }\n}\n```\n\n## Contributing\nContributions are immensely appreciated. Feel free to submit pull requests or to create issues to discuss any potential bugs or improvements.\n\n## Author\nGrove was created by @rafcabezas at [WillowTree, Inc](https://willowtreeapps.com).\n\n## License\nGrove is available under the [MIT license](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillowtreeapps%2Fgrove","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillowtreeapps%2Fgrove","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillowtreeapps%2Fgrove/lists"}