Swiftpack.co -  AlbGarciam/DependencyInjection as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
AlbGarciam/DependencyInjection
A library to inject your dependencies via property wrappers
.package(url: "https://github.com/AlbGarciam/DependencyInjection.git", from: "0.2.0")

๐Ÿ’‰ DependencyInjection

A library to inject your dependencies via property wrappers

Github Swift Swift Package Manager codecov

๐ŸŒŸ Features

DependencyInjection allows you to define the dependencies of your app. It exposes a property wrapper to make easier the injection in your instances. Every instance can be resolved at three different levels:

  • instance: Resolves a unique instance across the entire app
  • shared: Resolves the instance and allows it to be reused if it is needed on another object
  • global: The instance will act as a singleton

๐Ÿ— Usage

There are two separate steps when using DependencyInjection

Register dependecies

let module: Module = {
    instance(TypeAContract.self, TypeA.self)
    shared(TypeBContract.self, TypeB.self)
    global(TypeCContract.self, TypeC.self)
}

startInjection {
    registerModules(module)
}

Injecting instance

To inject an instance you can just use the property wrapper:

protocol Definition: Injectable {}
class Implementation: Definition {}

@Injected var instance: Definition // It will be Implementation

๐Ÿ›  Compatibility

This library can be used on iOS, macOS, iPadOS, watchOS and tvOS as it only relies on Foundation framework

โš™๏ธ Installation

You can use the Swift Package Manager by declaring DependencyInjection as a dependency in your Package.swift file:

.package(url: "https://github.com/AlbGarciam/DependencyInjection", from: "0.1.0")

DependencyInjection exposes 2 versions of the library, a static and a dynamic version.

๐Ÿป Etc.

  • Contributions are very welcome.
  • Attribution is appreciated (let's spread the word!), but not mandatory.

๐Ÿ‘จโ€๐Ÿ’ป Author

Alberto Garcรญa โ€“ @AlbGarciam

๐Ÿ‘ฎโ€โ™‚๏ธ License

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

GitHub

link
Stars: 3
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jackโ€™d and SCRUFF. We are two of the worldโ€™s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

0.2.0
1 week ago

Changes:

#3 Updates public API for registration process

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics