Getting Started
Add the ApplicationService or MonoBehaviourService to a class or MonoBehaviour.
[ApplicationService]public class GameManager{ public void LoadGame() { ... }}or
[MonoBehaviourService]public partial class GameManager : MonoBehaviour{ public void LoadGame() { ... }}And access easily then anywhere:
GameManager gameManager = ApplicationServices.Get<GameManager>();gameManager.LoadGame();Why use Services?
Section titled “Why use Services?”Simplify Code
Section titled “Simplify Code”OneLastClick.Services gives you a simple way to access shared systems without writing or maintaining singleton boilerplate.
Instead of writing common boiler plate such as:
public class GameManager : MonoBehaviour{ public static GameManager Instance { get; private set; }
private void Awake() { Instance = this; }}And accessing it everywhere like so:
GameManager.Instance.LoadGame();Just add the ApplicationService attribute to your class. An instance is created automatically at startup and can be accessed from anywhere.
[ApplicationService]public class GameManager{
}
ApplicationServices.Get<GameManager>().LoadGame();Decouple Your Code
Section titled “Decouple Your Code”It also allows you to decouple implementations from your game code by registering services as interfaces.
[ApplicationService(typeof(ISaveService))]public class SteamSaveService{}or
[ApplicationService(typeof(ISaveService))]public class XboxSaveService{}and then access platform agnostically via:
ApplicationServices.Get<ISaveService>().LoadGame();Only one class can be registered for a given type or interface. Exclude any alternative implementations using platform-specific compilation or other conditional compilation techniques.
MonoBehaviour Services
Section titled “MonoBehaviour Services”Use a MonoBehaviour service whenever you need references that can be assigned in the Inspector.
For example:
- Prefabs
- Addressable References
- Prefabs
- Etc.
Example Service:
using UnityEngine;using OneLastClick.Services.Attributes;
[MonoBehaviourService]public partial class AudioService : MonoBehaviour{ [SerializeField] private AudioSource _musicSource;
[SerializeField] private AudioClip _clickSound;
public void PlayClick() { _musicSource.PlayOneShot(_clickSound); }}Now the service can hold Unity references while still being resolved like any other service.
AudioService audioService = ApplicationServices.Get<AudioService>();
audioService.PlayClick();You need a configured Application Service Prefab to use MonoBehaviours as Application Services
All Notable Features
Section titled “All Notable Features”- 🔍 Automatic Service Discovery via
ApplicationServiceandMonoBehaviourServiceattributes. - 🧩 *Automatic Dependency Injection via the InjectService property attribute.
- 💡 Application Scoped Services via ApplicationServices.
- 🎬 Scene Scoped Services via SceneServices.
- ⚙️ Lifecycle Hooks via the IService interface. (OnServiceStart, OnServiceUpdate, OnServiceStop)
- 🚀 Disable Domain Reload Support: Automaticly start and stops services during scene load and unload, and when entering or exiting Play Mode.
*Automatic Dependency Injection can only be used within service