{"id":20555455,"url":"https://github.com/ivkuznetsov/dependencycontainer","last_synced_at":"2025-04-14T12:44:50.517Z","repository":{"id":188461240,"uuid":"678780793","full_name":"ivkuznetsov/DependencyContainer","owner":"ivkuznetsov","description":"DependencyContainer is an implementation of dependency injection for Swift applications, designed to simplify service management and improve code modularity.","archived":false,"fork":false,"pushed_at":"2024-11-07T12:42:15.000Z","size":12,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T01:53:35.068Z","etag":null,"topics":["architecture","dependency","dependency-injection","ios","macos","swift","swiftui"],"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/ivkuznetsov.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}},"created_at":"2023-08-15T11:09:04.000Z","updated_at":"2024-11-24T23:57:43.000Z","dependencies_parsed_at":"2023-11-18T15:27:07.230Z","dependency_job_id":"2d632f7a-3c58-45b2-af51-1c88b1d2455b","html_url":"https://github.com/ivkuznetsov/DependencyContainer","commit_stats":null,"previous_names":["ivkuznetsov/dependencycontainer"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivkuznetsov%2FDependencyContainer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivkuznetsov%2FDependencyContainer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivkuznetsov%2FDependencyContainer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivkuznetsov%2FDependencyContainer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivkuznetsov","download_url":"https://codeload.github.com/ivkuznetsov/DependencyContainer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248883418,"owners_count":21177207,"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":["architecture","dependency","dependency-injection","ios","macos","swift","swiftui"],"created_at":"2024-11-16T03:18:26.800Z","updated_at":"2025-04-14T12:44:50.483Z","avatar_url":"https://github.com/ivkuznetsov.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DependencyContainer\n\n**DependencyContainer** is an implementation of dependency injection for Swift applications, designed to simplify service management and improve code modularity.\n\n## Overview\n\nThis dependency injection container allows you to define, register, and resolve services in a clean and type-safe manner, facilitating better management of dependencies in your SwiftUI applications.\n\n### Defining Keys\n\nTo begin using the container, you first need to define keys for your services. These keys are used to identify the services when registering and resolving them.\n```swift\nextension DI {\n    static let network = Key\u003cany Network\u003e()\n    static let dataManager = Key\u003cany DataManager\u003e()\n    static let settings = Key\u003cany Settings\u003e()\n}\n```\n\n### Registering Services\n\nNext, you will register your services within the DI.Container. This step associates each service with its corresponding key.\n```swift\nextension DI.Container {\n    static func setup() {\n        register(DI.network, NetworkImp())\n        register(DI.dataManager, DataManagerImp())\n        register(DI.settings, SettingsImp())\n    }\n}\n```\n\n### Using Services in Classes\n\nYou can access the registered services in your classes by using the provided property wrappers. For example, in a class that conforms to ObservableObject, you can inject dependencies as follows:\n\n```swift\nclass SomeStateObject: ObservableObject {\n    @DI.Static(DI.network, \\.tokenUpdater) var network\n    @DI.RePublished(DI.settings) var settings\n}\n```\n\n### `RePublished` Property Wrapper\n\nThe `RePublished` property wrapper automatically redirects updates from the injected service to the enclosing `ObservableObject`, ensuring your UI stays in sync with the underlying data.\n\nRePublished property wrapper redirects update from a service to a container ObservableObject\n\n### Using Services in Views\n\nIn SwiftUI views, you can also inject and observe your services. For example:\n```swift\nstruct SomeView: View {\n    @DI.Observed(DI.dataManager) var data\n    \n    var body: some View {\n        // Your view content using the injected data manager\n    }\n}\n```\n\n## Meta\n\nIlya Kuznetsov – i.v.kuznecov@gmail.com\n\nDistributed under the MIT license. See ``LICENSE`` for more information.\n\n[https://github.com/ivkuznetsov](https://github.com/ivkuznetsov)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivkuznetsov%2Fdependencycontainer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivkuznetsov%2Fdependencycontainer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivkuznetsov%2Fdependencycontainer/lists"}