Skip to content

Simplified approach of dependency usage through propery wrapper

License

Notifications You must be signed in to change notification settings

VictorKreniski/Injected

Repository files navigation

Injected

Swift Version License

Overview

Injected is a Swift Package Manager (SPM) package that provides a property wrapper for dependency injection in Swift projects. It simplifies the process of injecting dependencies into your code, making it more modular and testable.

Features

  • @Injected Property Wrapper: Easily inject dependencies using the @Injected property wrapper.
  • InjectionKey Protocol: Implement the InjectionKey protocol for custom injection keys.
  • Shared State Management: Manage shared state with the InjectedValues structure.

Installation

Swift Package Manager

To integrate this library into your Xcode project using Swift Package Manager, follow these steps:

  1. Open your Xcode project.
  2. Navigate to the menu File > Swift Packages > Add Package Dependency....
  3. Enter the following URL of this repository: git@github.com:VictorKreniski/Injected.git.
  4. Click Next and select the version or branch you want to use.
  5. Click Next and then Finish.

The library will be automatically resolved and linked with your Xcode project.

Usage

  1. Import the Injected module:
import Injected
  1. Define an injection key using the InjectionKey protocol:
private struct TestInjectedValues: InjectionKey {
    static var currentValue: String = ""
}
  1. Use the @Injected property wrapper to inject dependencies:
@Injected(\.testValue) var testValue
  1. Set and get values using the injected property:
testValue = "Updated String"
print(testValue) // Output: "Updated String"

License

Injected is available under the MIT license. See the LICENSE file for more info.

Contact

For any questions or suggestions, feel free to open an issue.

About

Simplified approach of dependency usage through propery wrapper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages