An open API service indexing awesome lists of open source software.

https://github.com/alexanderlarsen/saneject

Dependency injection the Unity way
https://github.com/alexanderlarsen/saneject

dependency-injection di saneject serialized-interfaces unity unity-editor unity-inspector unity-tools unity3d

Last synced: 12 days ago
JSON representation

Dependency injection the Unity way

Awesome Lists containing this project

README

          





Saneject logo

![Unity](https://img.shields.io/badge/Unity-2022.3.12+-ff8383)
[![Tests](https://img.shields.io/github/actions/workflow/status/alexanderlarsen/Saneject/tests.yml?label=Tests)](https://github.com/alexanderlarsen/Saneject/actions/workflows/tests.yml)
[![Release](https://img.shields.io/github/v/release/alexanderlarsen/Saneject?include_prereleases&color=blue&label=Release)](https://github.com/alexanderlarsen/Saneject/releases)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow)](LICENSE)

Dependency injection the Unity way.

Inject dependencies in the Unity Editor, not Play Mode, by writing them directly into serialized fields at edit-time using familiar DI APIs, so everything stays visible in the Inspector, including interfaces.

No runtime container. No startup cost. No hidden wiring. No weird lifecycles. Just simple, deterministic edit-time DI that works with Unity, not around it.

## Mental model

1. Mark your fields, properties and methods with `[Inject]`.
2. Create a `Scope` that binds dependencies for `[Inject]` members, and add it to a scene or prefab.
3. Click **Inject** in the Unity Editor.
4. Dependencies are injected into serialized fields.
5. Start the game and enjoy fast startup with Unity’s normal lifecycle.

## Slide overview

A quick visual tour of how Saneject works, how editor-time DI differs from runtime DI, its core features, benefits, APIs, and examples.

[Open the full slide overview](https://saneject.dev/slides)

[![Preview of the Saneject slide overview](Docs/images/slides/slides-preview.webp)](https://saneject.dev/slides)

## Main features

| Feature | Description |
|--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|
| Editor-time injection | Resolve dependencies in the editor and store them as normal serialized references. |
| Inspector-visible wiring | Keep dependencies, including interfaces, visible and editable in the Inspector instead of hiding them behind a runtime container. |
| Fluent binding API | Declare bindings in `Scope` components with familiar DI-style syntax. |
| Serialized interfaces | Use `[SerializeInterface]` for interface fields, arrays, and lists without wrapper classes. |
| Scene, prefab, and context awareness | Control what gets injected where and how cross-context resolution behaves. |
| Runtime proxy bridging | Handle references Unity cannot serialize directly across scene and prefab boundaries. |
| Low runtime overhead | No runtime container, no reflection-based startup pass, and no extra lifecycle layer. |
| Built-in tooling | Use injection menus, batch injection, logging, validation, settings, analyzers, and more directly in the Unity Editor. |

For more features, see [Feature overview](https://saneject.dev/docs/getting-started/feature-overview).

## Try Saneject now

Add this URL to Unity Package Manager (Unity 2022.3.12 or newer):

```text
https://github.com/alexanderlarsen/Saneject.git?path=UnityProject/Saneject/Assets/Plugins/Saneject
```

Or download the [latest release](https://github.com/alexanderlarsen/Saneject/releases) and import the `Saneject` folder into your Unity project.

Then jump to [Quick start](https://saneject.dev/docs/getting-started/quick-start).

## Feedback appreciated

If you try Saneject and something works well, feels unclear, or seems broken, I would love to hear about it.

- If you find a bug, please open an [Issue](https://github.com/alexanderlarsen/Saneject/issues).
- If you want to share feedback, ideas, or first impressions, drop a note in [Discussions](https://github.com/alexanderlarsen/Saneject/discussions).

## Links

- [Docs](https://saneject.dev/docs/getting-started/introduction)
- [API](https://saneject.dev/api/Plugins.Saneject.Editor.Inspectors.SanejectInspector)
- [Releases](https://github.com/alexanderlarsen/Saneject/releases)
- [MIT license](https://github.com/alexanderlarsen/Saneject/blob/main/LICENSE)