Pragmatik Dev · Fast DI · Technical reference

Fast DI — public API

Namespace PragmatikDev.FastDI · Unity 6000.x. Fields only in v1; injection is idempotent for already-assigned serialized references.

Feature tutorials (examples)

Assemblies

Assembly Role
PragmatikDev.FastDI.Runtime Injection kernel, attributes, scopes, hierarchy/scene/project resolution.
PragmatikDev.FastDI.Editor Validation menu, diagnostics host, diagnostics toggles.
PragmatikDev.FastDI.TutorialFlat Optional showcase behaviours (FastDiDemoShowcase.cs) and tutorial scenes kept together under Tutorials/Flat.
PragmatikDev.FastDI.Tests.Shared Runtime test doubles (hierarchy types) shared with Edit Mode tests — not part of shipping runtime.
PragmatikDev.FastDI.Tests.EditMode / …PlayMode Automated tests (NUnit + Unity Test Framework).

InjectableBehaviour

Abstract base class for consumers. Declares [DefaultExecutionOrder(-32000)] so Awake/OnEnable runs injection early.

public abstract class InjectableBehaviour : MonoBehaviour
{
    protected virtual void Awake() => SceneInjection.Apply(this);
    protected virtual void OnEnable() => SceneInjection.Apply(this);
    protected virtual void OnDestroy() { /* releases GameObject-singleton hooks */ }
}

Subclass your behaviours from this type and mark instance fields with [Inject(…)] (properties are not supported in v1).

SceneInjection (static)

Member Description
Apply(InjectableBehaviour host) Resolves all [Inject] fields on the host that still need a value.
RegisterSingletonService<T>(T instance) Registers an application-wide singleton instance for type T (Scopes.Singleton).
RegisterSceneService<T>(Scene scene, T instance) Registers a scene-scoped instance for the given UnityEngine.SceneManagement.Scene.
ResetAllRegistries() Clears singleton/scene/GO-singleton stores and reflection caches — for tests and domain reload hygiene.

Editor only (inside #if UNITY_EDITOR in the package): DiagnosticsLoggingEnabled, DumpDiagnostics() for verbose resolve tracing.

[Inject]

[AttributeUsage(AttributeTargets.Field)]
public sealed class InjectAttribute : Attribute
{
    public InjectAttribute(Scopes scope = Scopes.Hierarchy);
    public Scopes Scope { get; }
}

Scopes

Value Semantics
Hierarchy (default) Resolve on self, then parents, then descendants — Component / interface implemented by a component.
Scene At most one instance per loaded scene; discovers MonoBehaviour or new() POCOs with public parameterless ctor.
Singleton Shared app-wide bucket keyed by CLR type; satisfy with RegisterSingletonService<T> before resolution.
GameObjectSingleton One instance per host GameObject for the field type (shared across multiple InjectableBehaviours on that GO).

InjectionException

Thrown when a required injection cannot be satisfied. Messages include scope, field type, and a scene path hint (for example '/Parent/Child').

Resolution notes

  • Register* calls must match the declared field type unless you bridge via generics yourself.
  • Hierarchy matches components by assignable type; duplicate assembly loads in the Editor can require matching test doubles in a runtime test assembly (see Tests/Shared in the asset).
  • Edit Mode tests that build hierarchies should parent GameObjects into a loaded Editor scene so Unity’s component queries behave consistently.

Editor menus

All under Unity menu Tools ▸ Pragmatik Dev ▸ Fast DI ▸ …

  • Validate Active Scene — runs SceneInjection.Apply on every active InjectableBehaviour and logs pass/fail lines.
  • Add Diagnostics Host (Persistent) — optional hierarchy object with diagnostics.
  • Enable / Disable Verbose Diagnostics Logging — toggles SceneInjection.DiagnosticsLoggingEnabled (Editor).

Optional component: Pragmatik Dev/Fast DI/Diagnostics Host (AddComponentMenu path on the diagnostics component in the package).

Tests & tutorials

  • Edit ModeAssets/PragmatikDev/FastDI/Tests/EditMode (+ Tests/Shared hierarchy doubles).
  • Play ModeAssets/PragmatikDev/FastDI/Tests/PlayMode.
  • Test Runner — select assemblies PragmatikDev.FastDI.Tests.EditMode / …PlayMode; Edit Mode tests require the Editor, not a built Player.
  • Tutorials — optional PragmatikDev.FastDI.TutorialFlat with reference scripts and checked-in tutorial scenes.

In-repo manual

After importing the asset, open Assets/PragmatikDev/FastDI/DOCUMENTATION.md and CHANGELOG.md for the authoritative user guide and version history. This web page is a concise API index; the package files stay the source of truth for prose and screenshots.

← All developer docs  ·  Tutorials  ·  Product page