Skip to content
One Last Click Docs

Dependency Injection

Services can use the a depenency injection system rather than using ApplicationServices.Get<T> or SceneServices.Get<T>

For example, a scene service can depend on an application service:

[MonoBehaviourService]
public partial class EnemyService : MonoBehaviour
{
[InjectService]
private SaveService _saveService;
}

This reduces the amount of code you need to write and makes it easier to read.

Any service, such as Pure C# or MonoBehaviour, using the InjectService attribute much use the partial modifier as Source Generation is used to set the value of the field.

A scene service can depend on an application service because the application service outlives the scene. However, an application service can not depend on a scene service because the scene services exist after the application services have been created.