Skip to content

Service Locator

The Service Locator handles dependency injection with automatic service discovery. Mark a class with [Service] and Ascendere registers it — no manual wiring.

LifetimeBehavior
SingletonOne instance shared across the entire game (default)
TransientNew instance created on every resolve
ScopedOne instance per scope (e.g. per scene)
[Service]
public class AudioManager : Node
{
public void Play(string clip) { }
}

To specify a lifetime:

[Service(Lifetime.Transient)]
public class MyFactory : Node { }
var audio = Services.Get<AudioManager>();
audio.Play("jump");

Services can depend on other services. Ascendere resolves the full dependency graph automatically.

[Service]
public class GameManager : Node
{
private readonly AudioManager _audio;
public GameManager(AudioManager audio)
{
_audio = audio;
}
}