All Projects → UniDi → UniDi

UniDi / UniDi

Licence: other
Dependency Injection for Unity

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to UniDi

Zenject-2019
Dependency Injection Framework for Unity3D
Stars: ✭ 2,567 (+3675%)
Mutual labels:  dependency-injection, zenject
AutoDI
Dependency injection made simple.
Stars: ✭ 87 (+27.94%)
Mutual labels:  dependency-injection, di-container
Swinject
Dependency injection framework for Swift with iOS/macOS/Linux
Stars: ✭ 4,958 (+7191.18%)
Mutual labels:  dependency-injection, di-container
unbox
Fast, simple, easy-to-use DI container
Stars: ✭ 45 (-33.82%)
Mutual labels:  dependency-injection, di-container
refuel
Lightweight dependency injection engine and DI-driven tools.
Stars: ✭ 21 (-69.12%)
Mutual labels:  dependency-injection, di-container
simple-container
Yet another DI container
Stars: ✭ 12 (-82.35%)
Mutual labels:  dependency-injection, di-container
hypo-container
A dependency injection container.
Stars: ✭ 16 (-76.47%)
Mutual labels:  dependency-injection, di-container
Gakko
Gakko - The Classroom App
Stars: ✭ 14 (-79.41%)
Mutual labels:  dependency-injection
simple-dijs
Simple Javascript Dependency Injection Container (DI) like Pimple, well tested browser/node - callbacks compatible Simple Javascript Dependency Injection Container (DI) like Pimple, well tested browser/node - ES6 Arrow Functions compatible
Stars: ✭ 18 (-73.53%)
Mutual labels:  dependency-injection
stashbox
A lightweight, fast, and portable dependency injection framework for .NET-based solutions.
Stars: ✭ 120 (+76.47%)
Mutual labels:  dependency-injection
alice
An additive dependency injection container for Golang.
Stars: ✭ 51 (-25%)
Mutual labels:  dependency-injection
SimpleConfig
No description or website provided.
Stars: ✭ 22 (-67.65%)
Mutual labels:  di-container
systemic
📦 A minimal dependency injection framework.
Stars: ✭ 53 (-22.06%)
Mutual labels:  dependency-injection
gocontainer
Simple Dependency Injection Container
Stars: ✭ 18 (-73.53%)
Mutual labels:  dependency-injection
Uragano
Uragano, A simple, high performance RPC library. Support load balancing, circuit breaker, fallback, caching, intercepting.
Stars: ✭ 28 (-58.82%)
Mutual labels:  dependency-injection
StartupModules
Startup modules for ASP.NET Core.
Stars: ✭ 33 (-51.47%)
Mutual labels:  dependency-injection
APICorePayLots
Web API designed in Asp.NET Core 3.1, using Dapper and Entity Framework Core, Repository Pattern, Identity
Stars: ✭ 13 (-80.88%)
Mutual labels:  dependency-injection
Inyector
Library to Implement Automatic dependency injection by Configuration over Scaned Assemblies
Stars: ✭ 13 (-80.88%)
Mutual labels:  dependency-injection
ThinkRchive
An app showing all details for various Lenovo Thinkpad models. Made to try out Jepack Compose for Android.
Stars: ✭ 84 (+23.53%)
Mutual labels:  dependency-injection
react-molecule
Molecule is a light-weight framework that lets you reason about inter-component communication, dependency injection and logic decoupling.
Stars: ✭ 35 (-48.53%)
Mutual labels:  dependency-injection

UniDi

CI Documentation

UniDi is a Dependency Injection container for Unity and a continuation of Zenject/Extenject. The UniDi is a project that seeks to refactor Zenject in order to:

  • Simplify maintenance
  • Encourage contributions
  • Split the work between multiple developers
  • Maximize extensibility

Related Projects

Table Of Contents

What is a DI container?

A DI Container is a software library that provides DI functionality and automates many of the tasks involved in Object Composition, Interception, and Lifetime Management. It’s an engine that resolves and manages object graphs.

Installation

You have a few different options to install UniDi into your Unity project:

  1. Unity Package Manger Probably the easiest way. Just add the git URL and let the package manager install it for you.
  2. Manual Installation Edit the project manifest file by hand.
  3. Install from a File Download a tarball and install it as a package.

Unity Package Manager

Open the Package Manager (UPM) in Unity Windows -> Package Manager.

Select + in the top-left of the UPM panel and select Add package from Git URL...

Enter https://github.com/UniDi/UniDi.git in the text box and click add.

More info: Unity Manual: Installing from a Git URL.

Syntax: URL example
Latest default branch "https://github.com/UniDi/UniDi.git"
Specific branch "https://github.com/UniDi/UniDi.git/#branch-name"
Specific version (tag) "https://github.com/UniDi/UniDi.git#v.0.0.1"
Commit hash "https://github.com//UniDi/UniDi.git#9e72f9d5a6a3da49..."

Manual Installation

Open Packages/manifest.json with your favorite text editor. Add the following line to the dependencies block.

{
  "dependencies": {
    "com.unidi.unidi": "https://github.com/unidi/unidi.git"
  },
  "testables": "com.unidi.unidi"
}

Notice: Unity Package Manager records the current commit to a lock entry of the manifest.json. To update to the latest version, change the "hash" value manually or just remove the lock entry to resolve the package.

{
  "version": "https://github.com/unidi/unidi.git",
  "depth": 0,
  "source": "git",
  "dependencies": {},
  "hash": "dd5027426f3dfecf2212fa7abe26365387ad080f"
}

TODO: Unity Manual about

Install from file

Download and extract a release to your machine. Press 'Add package from disk...' in the Unity Package Manager and select the package.json file in the extracted folder.

Usage

Injection

UniDi automates the injection of dependencies into your classes.

Constructor Injection

public class Mage
{
    ISpell _spell;

    public Mage(ISpell spell)
    {
        _spell = spell;
    }
}

Field Injection

public class Mage
{
    [Inject]
    ISpell _spell;
}

Field injection occurs immediately after the constructor is called. All fields that are marked with the [Inject] attribute are looked up in the container and given a value. Note that these fields can be private or public and injection will still occur.

Property Injection

public class Mage
{
    [Inject]
    public ISpell Spell
    {
        get;
        private set;
    }
}

Property injection works the same as field injection except is applied to C# properties. Just like fields, the setter can be private or public in this case.

Method Injection

public class Mage
{
    ISpell _spell;
    IMana _mana;

    [Inject]
    public void Init(ISpell spell, IMana mana)
    {
        _spell = spell;
        _mana = mana;
    }
}

Method Inject injection works very similarly to constructor injection.

Code example: Hello, World!

This code example logs a 'Hello, World!' in the console.

using UniDi;
using UnityEngine;

public class TestInstaller : MonoInstaller
{
    public override void InstallBindings()
    {
        Container.Bind<string>().FromInstance("Hello, World!");
        Container.Bind<Greeter>().AsSingle().NonLazy();
    }
}

public class Greeter
{
    public Greeter(string message)
    {
        Debug.Log(message);
    }
}

If you want to follow all the steps of this example, you can consult the docs TODO:here

Contributing

Contributing is welcome! Create a draft when you are still working on your contribution (and don't want to have it merged) or a PR to be reviewed. Contributing guidelines

License

UniDi contributions are licensed under the Apache 2.0 license, except for contributions copied from Extenject. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].