using Cysharp.Threading.Tasks; using UnityEngine; using VContainer; namespace BulletHellTemplate { /// /// Facade that exposes a single implementation chosen at runtime. /// Register exactly one concrete service (Offline, Firebase, WebSocket-SQL, etc.) /// in BackendLifetimeScope; all calls made through this manager are /// forwarded to that implementation. /// [DisallowMultipleComponent] public sealed class BackendManager : MonoBehaviour { /// /// Globally accessible backend service selected during application boot. /// public static IBackendService Service { get; private set; } private static bool isInitialized; private void Awake() { DontDestroyOnLoad(gameObject); } public static void SetBackendInitialized() => isInitialized = true; /// /// Waits until the backend is fully initialized. /// /// Returns true when initialized. public static async UniTask CheckInitialized() { // Wait until the static flag is set await UniTask.WaitUntil(() => isInitialized); return true; } /// /// VContainer injects the concrete implementation bound to . /// /// Concrete backend implementation. [Inject] public void Construct(IBackendService backend) { Service = backend; SetBackendInitialized(); Debug.Log("Backend Injected"); } } }