Code Monkey home page Code Monkey logo

dependency-injection's Introduction

Dependency Injection

๐Ÿš€ Dependency Injection

This package provides a simple and easy-to-use Dependency Injection (DI) solution for Swift projects. It is inspired by JSR-330 and uses a property wrapper named @Inject to inject dependencies into properties of classes, structs, and protocols.

โœจ Features

  • ๐Ÿ”„ Support for both prototype and singleton scopes

  • ๐Ÿ—๏ธ Initialisable protocol for classes with an init method

  • ๐Ÿ’‰ Injectable protocol for objects conforming to Initialisable

  • ๐Ÿ”— WeakObjectWrapper class for wrapping reference types as weak references

  • ๐ŸŽ Inject struct for property wrapper, enabling dependency injection into properties

  • ๐Ÿง  Context class for managing dependency registration and resolution

  • ๐Ÿ› ๏ธ AssemblyBuilder class for creating and configuring dependency assemblies

๐Ÿš€ Usage

  1. Import the DependencyInjection module in your project.

  2. Use the @Inject property wrapper on properties in your classes, structs, and protocols:

class MyClass {
    @Inject var dependency: MyDependency
}
  1. Utilize the AssemblyBuilder to register dependencies and configure their scope:
let assembly = AssemblyBuilder.instance
    .add(factory: { MyDependency() }, bindingName: "MyDependency", scope: .singleton)
    .build()
  1. Use the Context class to register the assembly and resolve dependencies (e.g., in AppDelegate):
Context.instance.register(assembly)

๐Ÿ”ง Compatibility

This library requires Swift 5.3 or later.

๐Ÿ“ฆ Installation

Install DependencyInjection using the Swift Package Manager by adding it as a dependency in your Package.swift file or directly in your Xcode project.

๐Ÿ“„ License

This code is licensed under the MIT License.

dependency-injection's People

Contributors

denismurphy avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.