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
- Host: GitHub
- URL: https://github.com/alexanderlarsen/saneject
- Owner: alexanderlarsen
- License: mit
- Created: 2025-07-05T19:15:11.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2026-04-12T09:41:48.000Z (15 days ago)
- Last Synced: 2026-04-12T10:23:16.656Z (15 days ago)
- Topics: dependency-injection, di, saneject, serialized-interfaces, unity, unity-editor, unity-inspector, unity-tools, unity3d
- Language: C#
- Homepage: https://alexanderlarsen.com
- Size: 12.8 MB
- Stars: 63
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://github.com/alexanderlarsen/Saneject/actions/workflows/tests.yml)
[](https://github.com/alexanderlarsen/Saneject/releases)
[](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)
[](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)