Lightweight dependency injection for Stride scripts. Register your
types once, mark public get/set properties with [Inject], and the library fills them in for
you — no service-locator boilerplate in every script.
| File | Role |
|---|---|
InjectAttribute |
Marks a public settable property for injection (Static singleton or Dynamic transient). |
InjectionService |
The type → instance registry: Register / Register<T> / IsRegistered. |
InjectionServicesHelper |
One-call setup: get/create the service, register your bindings, attach the processor. |
InjectionProcessor |
Fills every [Inject] property as scripts enter the scene, clears them on exit. |
1 — Register your services once (e.g. from a StartupScript):
using StrideDependencyInjectionSystem;
public class GameServices : StartupScript
{
public override void Start()
{
InjectionServicesHelper.SetGetAndConfigureServices(Services, out _, out _, e =>
{
e.Register(typeof(int), 42);
e.Register(typeof(WeaponDataProvider), new WeaponDataProvider { ProviderUrl = "127.0.0.1" });
});
}
}2 — Inject into any script — mark a public get/set property with [Inject]:
using StrideDependencyInjectionSystem;
public class Sword : SyncScript
{
[Inject, DataMemberIgnore] public WeaponDataProvider? Weapons { get; set; }
[Inject, DataMemberIgnore] public int Damage { get; set; }
public override void Update()
=> DebugText.Print($"{Damage} dmg via {Weapons?.ProviderUrl}", new(10, 10));
}Injected properties must be public with both a getter and a setter.
[DataMemberIgnore]keeps them out of the Game Studio inspector.
cd Demo
dotnet runThe Sword script prints its injected values on screen: proof the library wired them up.
One project, three operating systems: Stride picks Direct3D 11 or Vulkan from the machine that builds it. From the store it is one click — the app's play button, or:
strideassetstore demo com.nicogo.dependency-injectionMIT. See LICENSE.md.