Kanda Foundation 0.2.0
Loading...
Searching...
No Matches
AppServiceLocator Class Reference

An application-level service container which spans the lifetime of multiple scenes. If it is a root service which does not depend on others, you can register it in [RuntimeInitializeOnLoad] so it's available immediately. Otherwise, you wait for other services to be available, and register it in Awake. More...

Static Public Member Functions

static void ClearServices ()
 Clears all registered services.
 
static void Register< T > (T instance, bool overwriteExisting=false)
 
static T Get< T > ()
 
static async Task< T > GetAsync< T > (AsyncObjectResolutionOptions options=null)
 

Detailed Description

An application-level service container which spans the lifetime of multiple scenes. If it is a root service which does not depend on others, you can register it in [RuntimeInitializeOnLoad] so it's available immediately. Otherwise, you wait for other services to be available, and register it in Awake.

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
private static void RegisterMyService()
{
IMyService myService = new MyService();
AppServiceLocator.Register(myService);
}
An application-level service container which spans the lifetime of multiple scenes....
Definition AppServiceLocator.cs:26
private async void Awake()
{
var myService = await AppServiceLocator.GetAsync<IMyService>();
IMyOtherService otherService = new MyOtherService(myService);
AppServiceLocator.Register(otherService);
}

The documentation for this class was generated from the following file: