The primitive dependency injection system for prototypes assembled on the knee.
Installation as a unity module via a git link in PackageManager or direct editing of `Packages/manifest' is supported.json:
"com.elmortem.dependincyinjection": "https://github.com/elmortem/dependincyinjection.git",
Mark construtor or method with them if you want to inject parameters to instance.
public class LevelManager
{
private readonly AssetSystem _assetSystem;
[Inject]
public LevelManager(AssetSystem assetSystem)
{
_assetSystem = assetSystem;
}
}
public class Movement : MonoBehaviour
{
private MovementSystemConfig _movementSystemConfig;
[Inject]
public void Construct(MovementSystemConfig movementSystemConfig)
{
_movementSystemConfig = movementSystemConfig;
}
}
DI container class.
DIContainer.Root.BindAsSingle<LevelManager>();
Base DI interface.
public class AssetSystem
{
private readonly IDIMaker _maker;
[Inject]
public AssetSystem(IDIResolver resolver)
{
_maker = maker;
}
public AssetLoader MakeLoader()
{
return _maker.Create<AssetLoader>();
}
}
Collected from pieces of code on the Internet and various tutorials, completed with love for use in jams.
Support Unity 2019.3 or later.
Use for free.
Enjoy!