A library to inject your dependencies via property wrappers

Overview

๐Ÿ’‰ 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.

You might also like...
Toledo - a dependency injection library for Swift that statically generates resolvers at compile-time.

Toledo Toledo is a dependency injection library for Swift that statically generates resolvers at compile-time. Index Features Installation Usage Licen

Effective DI library for rapid development in 200 lines of code.
Effective DI library for rapid development in 200 lines of code.

Effective DI library for rapid development in 200 lines of code.

A collection of Swift Property Wrappers (formerly "Property Delegates")

๐ŸŒฏ ๐ŸŒฏ Burritos A collection of well tested Swift Property Wrappers. @AtomicWrite @Clamping @Copying @DefaultValue @DynamicUIColor @EnvironmentVariable

Helps you define secure storages for your properties using Swift property wrappers.

๐Ÿ” Secure Property Storage Helps you define secure storages for your properties using Swift property wrappers. ๐ŸŒŸ Features All keys are hashed using S

Easily validate your Properties with Property Wrappers ๐Ÿ‘ฎ
Easily validate your Properties with Property Wrappers ๐Ÿ‘ฎ

ValidatedPropertyKit enables you to easily validate your properties with the power of Property Wrappers. struct LoginView: View { @Validated(

A micro-framework that leverages Swift Property Wrappers to implement the Service Locator pattern

Locatable Context Locatable is a Swift micro framework that leverages Property Wrappers to implement the Service Locator pattern, through a custom att

Swift Property Wrappers, but in Objective-C. And done horribly.

TOPropertyAccessor is an open source, Objective-C abstract class. Similar to Realm's Cocoa API, it uses the dynamic nature of the Objective-C runtime to access the properties of any of its subclasses, and routes calling them through overridable access points.

Short examples and references to work with property wrappers in SwiftUI.

A Colection of useful playgrounds This repo contains a collection of useful swift playgrounds. PropertyWrappers Playground Contains small example of u

A set of SwiftUI dynamic property wrappers that provide a more familiar API for accessing the Contacts framework. (iOS, watchOS, macOS)

Connections Also available as a part of my SwiftUI+ Collection โ€“ just add it to Xcode 13+ A set of SwiftUI dynamic property wrappers that provide a mo

A simple way to handle dependency injection using property wrappers

Injektion Introduction A simple way to handle dependency injection using propert

A micro-framework that leverages Swift Property Wrappers to implement the Service Locator pattern

Locatable Context Locatable is a Swift micro framework that leverages Property Wrappers to implement the Service Locator pattern, through a custom att

A Collection of useful Swift property wrappers to make coding easier

Swift Property Wrappers A Collection of useful Swift property wrappers to make c

ProximitySensor - Property wrappers for using the Proximity Sensor from the SwiftUI app

ProximitySensor Property wrappers for using the Proximity Sensor from the SwiftU

Injection - Dependency injection using property wrappers

Dependency injection using property wrappers. Registering types: // injecting a

Inject JavaScript to all websites!

Inject Javascript Safari Extension Hi, so, you want to Inject Javascript to a website? Great. Since this is a very basic (demo) project it has not tha

Inject-Dylib - ObjC Code to Programmatically Perform Dylib Injection
Inject-Dylib - ObjC Code to Programmatically Perform Dylib Injection

Inject-Dylib ObjC Code to Programmatically Perform Dylib Injection. Code leveraged from Wojciech Regula's FirefoxStealer project (https://github.com/r

Inject Dylib - Swift code to programmatically perform dylib injection
Inject Dylib - Swift code to programmatically perform dylib injection

Inject_Dylib Swift code to programmatically perform dylib injection. You can als

WebViewCustomFont - WKWebView extension to addScript for inject a custom font-face
WebViewCustomFont - WKWebView extension to addScript for inject a custom font-face

WebViewCustomFont WKWebView extension to addScript for inject a custom font-face

LicensePlist is a command-line tool that automatically generates a Plist of all your dependencies, including files added manually
LicensePlist is a command-line tool that automatically generates a Plist of all your dependencies, including files added manually

LicensePlist is a command-line tool that automatically generates a Plist of all your dependencies, including files added manually(specifi

Releases(1.0.0)
  • 1.0.0(Dec 6, 2021)

    What's Changed

    • Add auto injection by @AlbGarciam in https://github.com/AlbGarciam/DependencyInjection/pull/7

    Full Changelog: https://github.com/AlbGarciam/DependencyInjection/compare/0.2.2...1.0.0

    Source code(tar.gz)
    Source code(zip)
  • 0.2.2(Oct 12, 2021)

    What's Changed

    • Add nullability checks to prevent nullable injections by @AlbGarciam in https://github.com/AlbGarciam/DependencyInjection/pull/5

    Full Changelog: https://github.com/AlbGarciam/DependencyInjection/compare/0.2.1...0.2.2

    Source code(tar.gz)
    Source code(zip)
  • 0.2.0(Sep 6, 2021)

Owner
Alberto Garcia
iOS developer at Openbank
Alberto Garcia
A simple way to handle dependency injection using property wrappers

Injektion Introduction A simple way to handle dependency injection using propert

Andrew McGee 2 May 31, 2022
Injection - Dependency injection using property wrappers

Dependency injection using property wrappers. Registering types: // injecting a

Alejandro Ramirez 3 Mar 14, 2022
Inject-Dylib - ObjC Code to Programmatically Perform Dylib Injection

Inject-Dylib ObjC Code to Programmatically Perform Dylib Injection. Code leveraged from Wojciech Regula's FirefoxStealer project (https://github.com/r

Cedric Owens 1 Jan 2, 2022
Inject Dylib - Swift code to programmatically perform dylib injection

Inject_Dylib Swift code to programmatically perform dylib injection. You can als

Cedric Owens 40 Sep 27, 2022
WebViewCustomFont - WKWebView extension to addScript for inject a custom font-face

WebViewCustomFont WKWebView extension to addScript for inject a custom font-face

Juyeon Lee 1 Aug 17, 2022
DIContainer Swift is an ultra-light dependency injection container made to help developers to handle dependencies easily. It works with Swift 5.1 or above.

?? DIContainer Swift It is an ultra-light dependency injection container made to help developers to handle dependencies easily. We know that handle wi

Victor Carvalho Tavernari 10 Nov 23, 2022
Kraken - Simple Dependency Injection container for Swift. Use protocols to resolve dependencies with easy-to-use syntax!

Kraken Photo courtesy of www.krakenstudios.blogspot.com Introduction Kraken is a simple Dependency Injection Container. It's aimed to be as simple as

Syed Sabir Salman-Al-Musawi 1 Oct 9, 2020
โšก๏ธ Capacitor plugin to register push notifications via Azure Notification Hub.

Azure Notification Hubs @jonz94/capacitor-azure-notification-hubs Capacitor plugin to register push notifications via Azure Notification Hub. Install

jonz94 2 Dec 19, 2022
null 4 May 22, 2022
Tranquillity is a lightweight but powerful dependency injection library for swift.

DITranquillity Tranquillity is a lightweight but powerful dependency injection library for swift. The name "Tranquillity" laid the foundation in the b

Ivlev Alexander 393 Dec 24, 2022