Skip to content

Mobiray/unity-di

Repository files navigation

UnityDI - Minimal Dependency Injection Framework

A lightweight DI tool for Unity that supports singleton services with constructor and method injection.

Installation

  1. Add to your Packages/manifest.json:
{
  "dependencies": {
    "com.mobiray.unity_di": "https://github.com/mobiray/unity-di.git"
  }
}
  1. Create a subclass of GameInstaller and register dependencies
public class MyInstaller : GameInstaller
{
    protected override void RegisterDependencies(Container container)
    {
        container.Register<ISomeService, SomeService>();
        container.RegisterSingleton<GameManager>();
    }
}
  1. Add this Installer to every scene where you want these dependencies to be injected.

  2. Use [Inject] annotation for injecting to method or constructor:

public class Player : MonoBehaviour
{
    private ISomeService _service;
    
    [Inject]
    public void Construct(ISomeService service)
    {
        _service = service;
    }
}

About

DI from mobiray

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Packages

No packages published

Languages